+1 (614) 348-7474

Copy

Free in USA

info@crocoapps.com

Copy

From 10:00 to 21:00

info@crocoapps.com

Copy

From 10:00 to 21:00

Fill out the brief

Online request

#

Example code in Unity

Crocoapps editorial

Crocoapps editorial

Reading time: 2 minutes

Table of contents

Example 1

Code is the main bot class from the multi-account Steam bot. It uses multithreading which allows you to parallelize multiple tasks.

using System;
using System.Threading;
using SteamApi;

namespace TestBot {
  /// <summary>
  /// Message Handler
  /// </summary>
  /// <param name="log">Logging level</param>
  /// <param name="message">Message body with Markdown markup</param>

  public delegate void TelegramMessageHandler(Telegram.TelegramLog log, string message);

  /// <summary>
  /// Main Steam bot
  /// </summary>

  public class MainBot : SteamBot {
    private bool working = true;
    private Thread confirmationThread;

    /// <summary>
    /// Message Handler
    /// </summary>

    public TelegramMessageHandler MessageHandler;

    /// <summary>
    /// Initializes a new instance of the MainBot class
    /// </summary>

    /// <param name="dataFile">Bot data file</param>
    /// <param name="name">Bot name<param>
    /// <param name="logging">Logging level</param>

    public MainBot(string dataFile, string name, LogOptions logging) : base(dataFile, name, logging) {
      confirmationThread = new Thread(confirmationThreadVoid);
    }

    /// <summary>
    /// Starts the confirmation flow
    /// </summary>

    public void StartConfirm() {
      SteamApi.DoLog("Confirming through proxy");
      confirmationThread.Start();
    }

    private void confirmationThreadVoid() {
      try {
        while (working) {
          SteamApi.DoDebug("Fetching confirmations");
          var mainConf = SteamConfirm.GetConfirmations();

          foreach (var c in mainConf) {
            SteamConfirm.AcceptConfirmation(c);
          }

          SteamApi.DoDebug("Confirmation have fetched");
          Thread.Sleep(10000);
        }
      }
      catch (Exception e) {
        SteamApi.DoLog("EXCEPTION: " + e.Message);
        SteamApi.DoLog("EXCEPTION STACK TRACE: " + e.StackTrace);
        MessageHandler(Telegram.TelegramLog.Errors, string.Format("Error:\n```\n{0}```", e));
        Thread.Sleep(10000);
        environment.exit(-1);
      }
    }

    protected override void mainThreadVoid() {
      try {
        while (working) {
          var incoming = SteamTrade.GetIncomingTradeoffers();

          foreach (var offer incoming) {
            if (offer.ItemsTo.Count == 0 && offer.ItemsFrom.Count > 0) {
              SteamApi.DoDebug("Got new items from main bot. Accepting...");
              SteamTrade.AcceptIncomingTrade(offer.ID.ToString());
              SteamApi.DoDebug("Updating bot inventory");
            }
            else {
              SteamApi.DoDebug(string.Format("Strange tradeto satellite from: {0}. Declining...", offer.From));
              SteamTrade.DeclineIncomingTrade(offer.ID.ToString());
            }

            Thread.Sleep(10000);
          }
        }
      }
      catch (Exception e) {
        SteamApi.DoLog("EXCEPTION: " + e.Message);
        SteamApi.DoLog("EXCEPTION STACK TRACE: " + e.StackTrace);
        MessageHandler(Telegram.TelegramLog.Errors, string.Format("Error:\n```\n{0}```", e));
        Thread.Sleep(10000);
        environment.exit(-1);
      }
    }

    /// <summary>
    /// Stop all bot threads (no wait for completion)
    /// </summary>

    public void Stop() {
      working = false;
    }
  }
}

Example 2

MyEvent and EventManager these scripts work in tandem with each other. This is our own implementation of events.

PanelActivityController - Shows how MyEvent and EventManager work. The script accepts a specific event and performs the specified set of actions. Specifically, turning on and off panels.

using UnityEngine;
using System.Collections.Generic;
using System.Runtime.InteropServices;

public class EventManager {
  //UI
  public static string SHOW_ERROR_TEXT = "SHOW_ERROR_TEXT";
  public static string SET_ACTIVE_PANEL = "SET_ACTIVE_PANEL";
  public static string UPDATE_SELECTED_OBJECT_STATS = "UPDATE_SELECTED_OBJECT_STATS";

  // GAME
  public static string SHOW_UNPARRENT_WALL = "SHOW_UNPARRENT_WALL";
  public static string CHECK_PARENT_TO_CALC = "CHECK_PARENT_TO_CALC";
  public static string UPDATE_MAP_LINE = "UPDATE_MAP_LINE";
  public static string DELETE_MENU_OBJ = "DELETE_MENU_OBJ";
  public static string CLEAR_ALL_STAFF = "CLEAR_ALL_STAFF";
  public static string DELETE_OBJ = "DELETE_OBJ";
  public static string SAVE_OBJ = "SAVE_OBJ";
  public static string SAVE_OBJ_LOCAL = "SAVE_OBJ_LOCAL";

  public static string PARAM_SOURCE = "PARAM_SOURCE";
  public static string PARAM_VALUE = "PARAM_VALUE";
  public static string PARAM_ACTION = "PARAM_ACTION";

  public class EventWrapper {
    public EventWrapper(OnEvent onEvent) {
      this.onEvent = onEvent;
    }

    public OnEvent onEvent;
    public delegate void OnEvent(MyEvent myEvent);
  }

  public static EventManager instance = new EventManager();
  public Dictionary<string, List<EventWrapper>> listeners = new Dictionary<string, List<EventWrapper>> ();

  void Dispatch(MyEvent customEvent) {
    List<EventWrapper> tempList = new List<EventWrapper> ();
    tempList.AddRange(listeners[customEvent.type]);

    foreach(EventWrapper listener in tempList) {
      listener.onEvent(customEvent);
    }
  }

  void AddListener(string type, EventWrapper listener) {
    if (!listeners.ContainsKey(type)) {
      listeners.Add(type, new List<EventWrapper>());
    }

    listeners[type].Add(listener);
  }

  public void DestroyAllListeners(string type) {
    if (listeners.ContainsKey(type)) {
      listeners[type].Clear();
    }
  }

  void RemoveListener(string type, EventWrapper wrapper) {
    if (listeners.ContainsKey(type)) {
      listeners [type].Remove(wrapper);
    }
  }

  public void FireEvent(string type, object parameter) {
    if (listeners.ContainsKey(type)) {
      MyEvent event1 = new MyEvent(type, parameter);
      dispatch(event1);
    }
  }

  public void FireEvent(string type) {
    FireEvent(type, null);
  }

  public void Listen (string type, EventWrapper handler) {
    AddListener(type, handler);
  }

  public void DestroyListener(string type, EventManager.EventWrapper wrapper) {
    if (wrapper != null) {
      RemoveListener(type, wrapper);
    }
    else {
      Debug.Log("Null listener for destroy type ");
    }
  }
}
using UnityEngine;
using System.Collections;

public class MyEvent {
  public stringtype;
  public object parameter;

  public MyEvent (string type, object parameter) {
    this.type = type;
    this.parameter = parameter;
  }

  public MyEvent(string type) {
    this.type = type;
  }
}

using UnityEngine;
using System.Collections;

[SerializeField]
public enum MenuState {
  logo=0,
  Enter = 1
  work = 2,
  order=3,
  Export = 4
}

public class PanelActivityController : MonoBehavior {
  public MenuState panel;
  protected GameObject content;
  EventManager.EventWrapper setPanelActivity;
  bool isActive = false;

  void OnEnable() {
    setPanelActivity = new EventManager.EventWrapper(delegate(MyEvent myEvent) {
      MenuState sentPanel = (MenuState)myEvent.parameter;
      UpdatePanelActivity(sentPanel);
    });

    EventManager.instance.Listen(EventManager.SET_ACTIVE_PANEL, setPanelActivity);
  }

  void OnDisable() {
    EventManager.instance.DestroyListener(EventManager.SET_ACTIVE_PANEL, setPanelActivity);
  }

  void Start() {
    content = transform.GetChild(0).gameObject;

    if (panel == MenuState.Logo) {
      content.SetActive(true);
    }
    else {
      content.SetActive(false);
    }
  }

  void UpdatePanelActivity(MenuState sentPanel) {
    if (isActive == false) {
      if (sentPanel == panel) {
        content.SetActive(true);
        isActive = true;
      }
      else {
        content.SetActive(false);
         isActive = false;
      }
    }
    else {
      content.SetActive(false);
      isActive = false;
    }
  }
}

A small UI manager. The UI in the application was built on a set of windows and simple switching between them - https://yadi. sk/d/dCe-teU9AFtZhA

A plugin script for working with a microphone. It was originally developed to work with a microphone on mobile devices, but is also suitable for working on absolutely any device that has a microphone. The bottom line is to be able to calibrate the microphone and catch events when the sound exceeds the volume of the maximum calibrated sound, half of this value - https://yadi.sk/d/7ff19RwwcgtV1Q

Team Manager - https://yadi.sk/d/1WcBt2sztzz9lA

A piece of skeletal animation code for a game entity - https: //www.dropbox.com/s/jtrntpvm6jfkx54/entity_animation.cpp?dl=0

C/C++ serialization/introspection library - https://github.com/gurudennis/CRealize

Author

Crocoapps editorial

Crocoapps editorial