public void removeObject(GameObject obj)
 {
     GridData data = objectToGridData[obj.GetHashCode()];
     this.updateGrid(data.fromX, data.fromY, data.toX, data.toY, -data.cost);
     objectToGridData.Remove(obj.GetHashCode());
     //Debug.Log(string.Format("{0} at ({1},{2}) ({3}, {4})", obj.GetHashCode(), data.fromX, data.fromY, data.toX, data.toY));
 }
 private UnitBase findTarget(GameObject target)
 {
     foreach (UnitBase unit in UnitHandler.units)
     {
         if (unit.unit.GetHashCode() == target.GetHashCode())
             return unit;
     }
     return null;
 }      
Example #3
0
 public static string GetID(GameObject g)
 {
     foreach(KeyValuePair<string,GameObject> entry in objects) {
         if (entry.Value.GetHashCode().Equals(g.GetHashCode())) {
             return entry.Key;
             break;
         }
     }
     return "UnregisteredObject";
 }
    internal void AddOnOutsideClickHandler(GameObject gameObject, Action action)
    {
        int hashCode = gameObject.GetHashCode();

        if (!_onOutsideClickHandlers.ContainsKey(hashCode))
        {
            _onOutsideClickHandlers.Add(hashCode, new ActionTracker(gameObject));
        }

        _onOutsideClickHandlers[hashCode].Add(action);
    }
Example #5
0
 public static Unit getUnit(GameObject gameObject)
 {
     int hashCode = gameObject.GetHashCode();
     if (unitMap.ContainsKey(hashCode)){
         return unitMap[hashCode];
     }
     else
     {
         return null;
     }
 }
 public void registerObject(GameObject obj, float x, float y, float width, float height, int cost)
 {
     GridData d = new GridData();
     d.cost = cost;
     d.xOffset = obj.transform.position.x - x;
     d.yOffset = obj.transform.position.y - y;
     getGridCoords(x - width/2, y - height/2, out d.fromX, out d.fromY);
     getGridCoords(x + width/2, y + height/2, out d.toX, out d.toY);
     objectToGridData[obj.GetHashCode()] = d;
     this.updateGrid(d.fromX, d.fromY, d.toX, d.toY, cost);
     //Debug.Log(string.Format("Registered object: {0} at ({1},{2}) ({3}, {4})", obj.GetHashCode(), d.fromX, d.fromY, d.toX, d.toY));
 }
    public static IEnumerator moveToPoint(GameObject subject, Vector3 targetPoint)
    {
        MotionAgent motionAgent;
        if (Instance.map.ContainsKey(subject.GetHashCode()))
        {
           motionAgent = Instance.map[subject.GetHashCode()];
            if (motionAgent.navMeshObstacle.enabled)
            {
                motionAgent.navMeshObstacle.enabled = false;
                yield return null;
                yield return null;
            }
            if (!motionAgent.navMeshAgent.enabled)
            {
                motionAgent.navMeshAgent.enabled = true;
            }
        }
        else
        {
            motionAgent = new MotionAgent(subject, targetPoint);
            motionAgent.navMeshObstacle.enabled = false;

            yield return null;

            yield return null;

            motionAgent.navMeshAgent.enabled = true;
            Instance.map.Add(subject.GetHashCode(), motionAgent);
        }

        //Instance.agentList.Add(motionAgent);

        motionAgent.isStop = false;
        motionAgent.navMeshAgent.SetDestination(targetPoint);
        yield return null;
        Debug.Log(motionAgent.navMeshAgent.remainingDistance);
        yield return motionAgent;
    }
        /// <summary>
        /// Creates this cache entry
        /// Automatically gets reference to the EntityTag of the Entity
        /// </summary>
        /// <param name="Entity">GameEntity to cache</param>
        public GameEntityCacheEntry(GameObject Entity)
        {
            if(Entity.tag != "GameEntity")
            {
                Debug.LogError("Attempted to cache a non GameEntity GameObject. Blocked");
                Entity = null;
                Tag = null;
            }

            this.Entity = Entity;

            Tag = Entity.GetComponent<EntityTag>();

            EntityHash = Entity.GetHashCode();
        }
    public void updateObjectPosition(GameObject obj)
    {
        GridData data = objectToGridData[obj.GetHashCode()];

        // Remove old weight from old positions
        this.updateGrid(data.fromX, data.fromY, data.toX, data.toY, -data.cost);

        // calculate new positions
        var width = data.toX - data.fromX;
        var height = data.toY - data.fromY;
        getGridCoords(obj.transform.position.x + data.xOffset - width/2, obj.transform.position.y + data.yOffset - height/2, out data.fromX, out data.fromY);
        getGridCoords(obj.transform.position.x + data.xOffset + width/2, obj.transform.position.y + data.yOffset + height/2, out data.toX, out data.toY);

        // update map
        objectToGridData[obj.GetHashCode()] = data;

        // Add weight to new positions
        this.updateGrid(data.fromX, data.fromY, data.toX, data.toY, -data.cost);

        //Debug.Log(string.Format("{0} at ({1},{2}) ({3}, {4})", obj.GetHashCode(), data.fromX, data.fromY, data.toX, data.toY));
    }
Example #10
0
    private bool HasGameObjectInHeirarchy(GameObject gameObject, int hashCodeToSearchFor)
    {
        if (gameObject.GetHashCode() == hashCodeToSearchFor)
            return true;

        foreach (Transform child in gameObject.transform)
        {
            if (HasGameObjectInHeirarchy(child.gameObject, hashCodeToSearchFor))
                return true;
        }

        return false;
    }
Example #11
0
    private void EvalutateOnOutsideClick(GameObject gameObjectBeingClicked)
    {
        int hashOfClickedItem = gameObjectBeingClicked.GetHashCode();

        foreach (var kvp in _onOutsideClickHandlers)
        {
            // Create a strong reference to this variable so that it can't be collected after "HasExpired" evalutes
            var gameObject = kvp.Value.GameObject;

            if (!kvp.Value.HasExpired && !HasGameObjectInHeirarchy(gameObject, hashOfClickedItem))
            {
                kvp.Value.Execute();
            }
        }
    }
Example #12
0
	/// <summary>
	/// Removes a GameObject as a subjects of
	/// this panel's transitions.
	/// </summary>
	/// <param name="go">GameObject to be removed as a subject.</param>
	public void RemoveSubject(GameObject go)
	{
		int hash = go.GetHashCode();

		if (!subjects.ContainsKey(hash))
			return;

		subjects.Remove(hash);

		for (int i = 0; i < Transitions.list.Length; ++i)
			Transitions.list[i].RemoveSubSubject(go);

		// Remove the subject from any parent container as well:
		if (container != null)
			container.RemoveSubject(go);
	}
Example #13
0
	/// <summary>
	/// Adds a GameObject as a subject of this
	/// panel's transitions.
	/// </summary>
	/// <param name="go">GameObject to be added as a subject.</param>
	public void AddSubject(GameObject go)
	{
		int hash = go.GetHashCode();

		if (subjects.ContainsKey(hash))
			return;

		subjects.Add(hash, go);

		for (int i = 0; i < Transitions.list.Length; ++i)
			Transitions.list[i].AddSubSubject(go);

		// Add the subject to any parent container as well:
		if (container != null)
			container.AddSubject(go);
	}
	/// <summary>
	/// Removes a GameObject as a subjects of
	/// this panel's transitions.
	/// </summary>
	/// <param name="go">GameObject to be removed as a subject.</param>
	public void RemoveSubject(GameObject go)
	{
		int hash = go.GetHashCode();

		if (!subjects.ContainsKey(hash))
			return;

		subjects.Remove(hash);

		for (int i = 0; i < Transitions.list.Length; ++i)
			Transitions.list[i].RemoveSubSubject(go);
	}
Example #15
0
 public static void add(GameObject gameObject,Unit unit)
 {
     unitMap.Add(gameObject.GetHashCode(), unit);
 }