public static AKRESULT RegisterGameObj(UnityEngine.GameObject in_gameObjectID, string in_pszObjName) {
		AKRESULT res = RegisterGameObjInternal_WithName((int)in_gameObjectID.GetInstanceID(), in_gameObjectID.name);
		if( res == AKRESULT.AK_Success )
		{
			RegisteredGameObjects.Add(in_gameObjectID.GetInstanceID());
		}

		return res;
	}
	public static AKRESULT RegisterGameObj(UnityEngine.GameObject in_gameObjectID, uint in_uListenerMask) {
		AKRESULT res = RegisterGameObjInternal_WithMask((int)in_gameObjectID.GetInstanceID(), (uint)in_uListenerMask);
		if( res == AKRESULT.AK_Success )
		{
			RegisteredGameObjects.Add(in_gameObjectID.GetInstanceID());
		}

		return res;
	}
	public static AKRESULT RegisterGameObj(UnityEngine.GameObject in_gameObjectID) {
		AKRESULT res = RegisterGameObjInternal((int)in_gameObjectID.GetInstanceID());
		if( res == AKRESULT.AK_Success )
		{
			RegisteredGameObjects.Add(in_gameObjectID.GetInstanceID());
		}

		return res;
	}
Esempio n. 4
0
	public static AKRESULT RegisterGameObj(UnityEngine.GameObject in_gameObjectID) {
	
		if (!AkSoundEngine.IsInitialized())
			return AKRESULT.AK_Fail;
			
		AKRESULT res = RegisterGameObjInternal((int)in_gameObjectID.GetInstanceID());
		if( res == AKRESULT.AK_Success )
		{
			RegisteredGameObjects.Add(in_gameObjectID.GetInstanceID());
		}

		return res;
	}
Esempio n. 5
0
  public static uint DynamicSequenceOpen(UnityEngine.GameObject in_gameObjectID, uint in_uFlags, AkCallbackManager.EventCallback in_pfnCallback, object in_pCookie) {
    
		uint tempin_gameObjectID;
		if ( in_gameObjectID != null )
		{
			tempin_gameObjectID = (uint)in_gameObjectID.GetInstanceID();
			// Note: if AkGameObjectTracker is already attached, the following code will be bypassed.
			if (in_gameObjectID.GetComponent<AkGameObject>() == null)
			{
				in_gameObjectID.AddComponent<AkGameObject>();
			}
		}
		else
		{
			tempin_gameObjectID = unchecked((uint)-1);
		}
		
		
		in_pCookie = new AkCallbackManager.EventCallbackPackage(in_pfnCallback, in_pCookie);
    {
      uint ret = AkSoundEnginePINVOKE.CSharp_DynamicSequenceOpen__SWIG_1(tempin_gameObjectID, in_uFlags, (IntPtr)0, (IntPtr)in_pCookie.GetHashCode());

      return ret;
    }
  }
Esempio n. 6
0
 internal static void Add(UnityEngine.Object obj)
 {
     if (obj != null)
     {
         Add(obj.GetInstanceID());
     }
 }
Esempio n. 7
0
		public static Texture2D GetAssetPreview(UnityEngine.Object asset)
		{
			if (asset != null)
			{
				return AssetPreview.GetAssetPreview(asset.GetInstanceID());
			}
			return null;
		}
 internal static bool ShowAtPosition(UnityEngine.Object targetObj, Rect activatorRect, bool showLabelIcons)
 {
   int instanceId = targetObj.GetInstanceID();
   bool flag = DateTime.Now.Ticks / 10000L < IconSelector.s_LastClosedTime + 50L;
   if (instanceId == IconSelector.s_LastInstanceID && flag)
     return false;
   Event.current.Use();
   IconSelector.s_LastInstanceID = instanceId;
   if ((UnityEngine.Object) IconSelector.s_IconSelector == (UnityEngine.Object) null)
     IconSelector.s_IconSelector = ScriptableObject.CreateInstance<IconSelector>();
   IconSelector.s_IconSelector.Init(targetObj, activatorRect, showLabelIcons);
   return true;
 }
 internal static void RemoveSavedFoldout(string uniqueID, UnityEngine.Object target, int index = 0)
 {
     string baseString = "Fold: " + target.GetInstanceID().ToString() + " - " + uniqueID;
     string curString = baseString + index;
     string nextString = baseString + ++index;
     
     while (EditorPrefs.HasKey(nextString))
     {
         bool nextBool = EditorPrefs.GetBool(nextString);
         EditorPrefs.SetBool(curString, nextBool);
         nextString = baseString + ++index;
     }
 }
Esempio n. 10
0
    /** Serializes a Unity Reference. Serializer references such as Transform, GameObject, Texture or other unity objects */
    public override void AddUnityReferenceValue(string key, UnityEngine.Object value)
    {
        //Segment --- Should be identical to a segment in AddUnityReferenceValue/AddValue
        BinaryWriter stream = writerStream;

        AddVariableAnchor (key);

        if (value == null) {
            stream.Write ((byte)0);//Magic number indicating a null reference
            return;
        }

        //Magic number indicating that the data is written and not null
        stream.Write ((byte)1);
        //Segment --- End

        if (value == active.gameObject) {
            stream.Write (-128);//Magic number (random) indicates that the reference is the A* object
        } else if (value == active.transform) {
            stream.Write (-129);
        } else {
            stream.Write (value.GetInstanceID ());
        }
        stream.Write (value.name);

        //Write scene path if the object is a Component or GameObject
        Component component = value as Component;
        GameObject go = value as GameObject;

        if (component == null && go == null) {
            stream.Write ("");
        } else {
            if (go == null) {
                go = component.gameObject;
            }
            string path = go.name;

            while (go.transform.parent != null) {
                go = go.transform.parent.gameObject;
                path = go.name+"/" +path;
            }
            stream.Write (path);
        }

        if (writeUnityReference_Editor != null) {
            stream.Write (true);
            writeUnityReference_Editor (this,value);
        } else {
            stream.Write (false);
        }
    }
Esempio n. 11
0
        public static void LogSingleInstance(UnityEngine.Object instanceToLog, params object[] toLog)
        {
            int instanceId;

            if (instanceDict.TryGetValue(instanceToLog.GetType(), out instanceId))
            {
                if (instanceId == instanceToLog.GetInstanceID())
                    Log(toLog);
            }
            else
            {
                instanceDict[instanceToLog.GetType()] = instanceToLog.GetInstanceID();
                Log(toLog);
            }
        }
Esempio n. 12
0
		internal static bool ShowAtPosition(UnityEngine.Object targetObj, Rect activatorRect, bool showLabelIcons)
		{
			int instanceID = targetObj.GetInstanceID();
			long num = DateTime.Now.Ticks / 10000L;
			bool flag = num < IconSelector.s_LastClosedTime + 50L;
			if (instanceID != IconSelector.s_LastInstanceID || !flag)
			{
				Event.current.Use();
				IconSelector.s_LastInstanceID = instanceID;
				if (IconSelector.s_IconSelector == null)
				{
					IconSelector.s_IconSelector = ScriptableObject.CreateInstance<IconSelector>();
				}
				IconSelector.s_IconSelector.Init(targetObj, activatorRect, showLabelIcons);
				return true;
			}
			return false;
		}
Esempio n. 13
0
  public static uint DynamicSequenceOpen(UnityEngine.GameObject in_gameObjectID, uint in_uFlags, AkCallbackManager.EventCallback in_pfnCallback, object in_pCookie) {
    
		uint tempin_gameObjectID;
		if ( in_gameObjectID != null )
		{
			tempin_gameObjectID = (uint)in_gameObjectID.GetInstanceID();
			// Note: if AkGameObjectTracker is already attached, the following code will be bypassed.
			if (in_gameObjectID.GetComponent<AkGameObject>() == null)
			{
				in_gameObjectID.AddComponent<AkGameObject>();

				// Note: We have missed AkGameObject.Awake() of this run to register. 
				// So we take over its work by inlining it here.
				AkSoundEngine.RegisterGameObj(in_gameObjectID, in_gameObjectID.name);
			
				//Set the original position
				AkSoundEngine.SetObjectPosition(
		            in_gameObjectID, 
		            in_gameObjectID.transform.position.x, 
		            in_gameObjectID.transform.position.y, 
		            in_gameObjectID.transform.position.z, 
		            in_gameObjectID.transform.forward.x,
		            in_gameObjectID.transform.forward.y, 
		            in_gameObjectID.transform.forward.z
		        	);
			}
		}
		else
		{
			tempin_gameObjectID = unchecked((uint)-1);
		}
		
		
		in_pCookie = new AkCallbackManager.EventCallbackPackage(in_pfnCallback, in_pCookie);
    {
      uint ret = AkSoundEnginePINVOKE.CSharp_DynamicSequenceOpen__SWIG_1(tempin_gameObjectID, in_uFlags, (IntPtr)0, (IntPtr)in_pCookie.GetHashCode());

      return ret;
    }
  }
Esempio n. 14
0
		public void Cache (UnityEngine.Object obj, float life)
		{
			CacheObject cache = null;
			assetDic.TryGetValue(obj.name, out cache);

			if (cache == null)
			{
				cache = new CacheObject(life);
				cache.id = obj.GetInstanceID();
				cache.objName = obj.name;
				cache.obj = obj;
				cache.remainingLife = life;
				cache.referCount = 1;

				assetDic[cache.objName] = cache;
				indexDic[cache.id] = cache;
			}
			else
			{
				cache.referCount++;
			}
		}
Esempio n. 15
0
 public void UnlinkOnDestroyRemove(UnityEngine.GameObject obj)
 {
     #if DEBUG
     string[] containing = _unlinkOnDestroy.Select(x => x.ToString()).ToArray();
     Debug.Log("GameObjectTopInfo.UnlinkOnDestroyRemove " + obj + " id " + obj.GetInstanceID() + " from " + gameObject + " id " + gameObject.GetInstanceID() + " containing: " + string.Join(",", containing));
     #endif
     if (!_unlinkOnDestroy.Contains(obj))
     {
         //				Picus.Sys.Debug.Throw("GameObjectTopInfo.UnlinkToDestroyRemove " + obj + " not in", true);
         return;
     }
     _unlinkOnDestroy.Remove(obj);
 }
Esempio n. 16
0
 protected static int HashAdd(int current, UnityEngine.Object obj) {
     if (obj != null) {
         return MadHashCode.Add(current, obj.GetInstanceID());
     } else {
         return MadHashCode.Add(current, null);
     }
 }
Esempio n. 17
0
 public void UnlinkOnDestroyAdd(UnityEngine.GameObject obj)
 {
     #if DEBUG
     string[] containing = _unlinkOnDestroy.Select(x => x.ToString()).ToArray();
     Debug.Log("GameObjectTopInfo.UnlinkOnDestroyAdd " + obj + " id " + obj.GetInstanceID()+ " to " + gameObject + " id " + gameObject.GetInstanceID() + " containing: " + string.Join(",", containing));
     #endif
     if (_unlinkOnDestroy.Contains(obj))
     {
         Picus.Sys.Debug.Throw("GameObjectTopInfo.UnlinkToDestroyAdd " + obj + " already added", true);
         return;
     }
     _unlinkOnDestroy.Add(obj);
 }
Esempio n. 18
0
  public static uint PostEvent(string in_pszEventName, UnityEngine.GameObject in_gameObjectID) {
    
		uint tempin_gameObjectID;
		if ( in_gameObjectID != null )
		{
			tempin_gameObjectID = (uint)in_gameObjectID.GetInstanceID();
			// Note: if AkGameObjectTracker is already attached, the following code will be bypassed.
			if (in_gameObjectID.GetComponent<AkGameObject>() == null)
			{
				in_gameObjectID.AddComponent<AkGameObject>();

				// Note: We have missed AkGameObject.Awake() of this run to register. 
				// So we take over its work by inlining it here.
				AkSoundEngine.RegisterGameObj(in_gameObjectID, in_gameObjectID.name);
			
				//Set the original position
				AkSoundEngine.SetObjectPosition(
		            in_gameObjectID, 
		            in_gameObjectID.transform.position.x, 
		            in_gameObjectID.transform.position.y, 
		            in_gameObjectID.transform.position.z, 
		            in_gameObjectID.transform.forward.x,
		            in_gameObjectID.transform.forward.y, 
		            in_gameObjectID.transform.forward.z
		        	);
			}
		}
		else
		{
			tempin_gameObjectID = unchecked((uint)-1);
		}
		
		
    {
      uint ret = AkSoundEnginePINVOKE.CSharp_PostEvent__SWIG_11(in_pszEventName, tempin_gameObjectID);

      return ret;
    }
  }
Esempio n. 19
0
  public static AKRESULT ExecuteActionOnEvent(uint in_eventID, AkActionOnEventType in_ActionType, UnityEngine.GameObject in_gameObjectID, int in_uTransitionDuration) {
    
		uint tempin_gameObjectID;
		if ( in_gameObjectID != null )
		{
			tempin_gameObjectID = (uint)in_gameObjectID.GetInstanceID();
			// Note: if AkGameObjectTracker is already attached, the following code will be bypassed.
			if (in_gameObjectID.GetComponent<AkGameObject>() == null)
			{
				in_gameObjectID.AddComponent<AkGameObject>();

				// Note: We have missed AkGameObject.Awake() of this run to register. 
				// So we take over its work by inlining it here.
				AkSoundEngine.RegisterGameObj(in_gameObjectID, in_gameObjectID.name);
			
				//Set the original position
				AkSoundEngine.SetObjectPosition(
		            in_gameObjectID, 
		            in_gameObjectID.transform.position.x, 
		            in_gameObjectID.transform.position.y, 
		            in_gameObjectID.transform.position.z, 
		            in_gameObjectID.transform.forward.x,
		            in_gameObjectID.transform.forward.y, 
		            in_gameObjectID.transform.forward.z
		        	);
			}
		}
		else
		{
			tempin_gameObjectID = unchecked((uint)-1);
		}
		
		
    {
      AKRESULT ret = (AKRESULT)AkSoundEnginePINVOKE.CSharp_ExecuteActionOnEvent__SWIG_2(in_eventID, (int)in_ActionType, tempin_gameObjectID, in_uTransitionDuration);

      return ret;
    }
  }
Esempio n. 20
0
        //============== Custom Simpler Serializer
        /** Serializes a Unity Reference. Serializer references such as Transform, GameObject, Texture or other unity objects */
        public virtual void AddUnityReferenceValue(string key, UnityEngine.Object value)
        {
            //Segment --- Should be identical to a segment in AddUnityReferenceValue/AddValue
            BinaryWriter stream = writerStream;

            AddVariableAnchor (key);

            if (value == null) {
                stream.Write ((byte)0);//Magic number indicating a null reference
                return;
            }

            //Magic number indicating that the data is written and not null
            stream.Write ((byte)1);
            //Segment --- End

            if (value == active.gameObject) {
                stream.Write (-128);//Magic number (random) indicates that the reference is the A* object
            } else if (value == active.transform) {
                stream.Write (-129);
            } else {
                stream.Write (value.GetInstanceID ());
            }
            stream.Write (value.name);

            //Write scene path if the object is a Component or GameObject
            Component component = value as Component;
            GameObject go = value as GameObject;

            if (component == null && go == null) {
                stream.Write ("");
            } else {
                if (component != null && go == null) {
                    go = component.gameObject;
                }

                UnityReferenceHelper helper = go.GetComponent<UnityReferenceHelper>();

                if (helper == null) {
                    Debug.Log ("Adding UnityReferenceHelper to Unity Reference '"+value.name+"'");
                    helper = go.AddComponent<UnityReferenceHelper>();
                }

                //Make sure it has a unique GUID
                helper.Reset ();

                stream.Write (helper.GetGUID ());

                /*if (go == null) {
                    go = component.gameObject;
                }
                string path = go.name;

                while (go.transform.parent != null) {
                    go = go.transform.parent.gameObject;
                    path = go.name+"/" +path;
                }
                stream.Write (path);*/
            }

            /*if (writeUnityReference_Editor != null) {
                stream.Write (true);
                writeUnityReference_Editor (this,value);
            } else {*/

                //Backwards compability
                stream.Write (false);
            //}
        }
Esempio n. 21
0
  public static AKRESULT SetObjectPosition(UnityEngine.GameObject in_GameObjectID, float PosX, float PosY, float PosZ, float OrientationX, float OrientationY, float OrientationZ) {
    
		uint tempin_GameObjectID;
		if ( in_GameObjectID != null )
		{
			tempin_GameObjectID = (uint)in_GameObjectID.GetInstanceID();
			// Note: if AkGameObjectTracker is already attached, the following code will be bypassed.
			if (in_GameObjectID.GetComponent<AkGameObject>() == null)
			{
				in_GameObjectID.AddComponent<AkGameObject>();

				// Note: We have missed AkGameObject.Awake() of this run to register. 
				// So we take over its work by inlining it here.
				AkSoundEngine.RegisterGameObj(in_GameObjectID, in_GameObjectID.name);
			
				//Set the original position
				AkSoundEngine.SetObjectPosition(
		            in_GameObjectID, 
		            in_GameObjectID.transform.position.x, 
		            in_GameObjectID.transform.position.y, 
		            in_GameObjectID.transform.position.z, 
		            in_GameObjectID.transform.forward.x,
		            in_GameObjectID.transform.forward.y, 
		            in_GameObjectID.transform.forward.z
		        	);
			}
		}
		else
		{
			tempin_GameObjectID = unchecked((uint)-1);
		}
		
		
    {
      AKRESULT ret = (AKRESULT)AkSoundEnginePINVOKE.CSharp_SetObjectPosition(tempin_GameObjectID, PosX, PosY, PosZ, OrientationX, OrientationY, OrientationZ);

      return ret;
    }
  }
Esempio n. 22
0
  public static AKRESULT GetPlayingIDsFromGameObject(UnityEngine.GameObject in_GameObjId, ref uint io_ruNumIDs, uint[] out_aPlayingIDs) {
    
		uint tempin_GameObjId;
		if ( in_GameObjId != null )
		{
			tempin_GameObjId = (uint)in_GameObjId.GetInstanceID();
			// Note: if AkGameObjectTracker is already attached, the following code will be bypassed.
			if (in_GameObjId.GetComponent<AkGameObject>() == null)
			{
				in_GameObjId.AddComponent<AkGameObject>();

				// Note: We have missed AkGameObject.Awake() of this run to register. 
				// So we take over its work by inlining it here.
				AkSoundEngine.RegisterGameObj(in_GameObjId, in_GameObjId.name);
			
				//Set the original position
				AkSoundEngine.SetObjectPosition(
		            in_GameObjId, 
		            in_GameObjId.transform.position.x, 
		            in_GameObjId.transform.position.y, 
		            in_GameObjId.transform.position.z, 
		            in_GameObjId.transform.forward.x,
		            in_GameObjId.transform.forward.y, 
		            in_GameObjId.transform.forward.z
		        	);
			}
		}
		else
		{
			tempin_GameObjId = unchecked((uint)-1);
		}
		
		
    {
      AKRESULT ret = (AKRESULT)AkSoundEnginePINVOKE.CSharp_GetPlayingIDsFromGameObject(tempin_GameObjId, ref io_ruNumIDs, out_aPlayingIDs);

      return ret;
    }
  }
	/**
   * The interface of dialog system in the game.
   * A player chats with avatar by typing text in the console,
   * then the text would be sent to OAC by this method.
   * 
   * @param text the chat text to be sent.
   * @param source GameObject that sent the communication.
   */
	public void SendSpeechContent(string text, UnityEngine.GameObject source)
	{
		text = text.TrimEnd('\n');
		// Don't send a message unless we are initialized to connect to
		// a server
		if(!_isInitialized)
		{
			OCLogger.Warn("Avatar[" + _ID + "]: Received '" + text +
				"' from player but I am not connected to an OAC.");
			return;
		}
		OCLogger.Debugging("Avatar[" + _ID + "]: Received '" + text + "' from player.");

		// Avoid creating messages if the destination (avatar brain) isn't available 
		if(!IsElementAvailable(_brainID))
		{
			return;
		}
      
		System.Text.StringBuilder speechMsg = new System.Text.StringBuilder();
		speechMsg.Append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");

		speechMsg.Append("<oc:embodiment-msg xmlns:oc=\"http://www.opencog.org/brain\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.opencog.org/brain BrainProxyAxon.xsd\">\n");
		speechMsg.Append("<communication source-id=\"");
		speechMsg.Append(source.GetInstanceID());
		speechMsg.Append("\" timestamp=\"");
		speechMsg.Append(GetCurrentTimestamp());
		speechMsg.Append("\">");
		speechMsg.Append(text);
		speechMsg.Append("</communication>");
		speechMsg.Append("</oc:embodiment-msg>");
      
		OCMessage message = OCMessage.CreateMessage(_ID, _brainID, OCMessage.MessageType.RAW, speechMsg.ToString());
      
		// Add the message to the sending queue.
		lock(_messageSendingLock)
		{
			_messagesToSend.Add(message);
		}
	}
	public void SendMoveActionDone(UnityEngine.GameObject obj, UnityEngine.Vector3 startPos, UnityEngine.Vector3 endPos)
	{
		if(obj == GameObject.FindGameObjectWithTag("OCAGI"))
		{
			return;
		}
		
		string timestamp = GetCurrentTimestamp();
		XmlDocument doc = new XmlDocument();
		XmlElement root = MakeXMLElementRoot(doc);

		XmlElement agentSignal = (XmlElement)root.AppendChild(doc.CreateElement("agent-signal"));
		agentSignal.SetAttribute("id", obj.GetInstanceID().ToString());
    
		agentSignal.SetAttribute("timestamp", timestamp);
		XmlElement actionElement = (XmlElement)agentSignal.AppendChild(doc.CreateElement(OCEmbodimentXMLTags.ACTION_ELEMENT));
        
		// note that the name and the action-instance-name are different
		// ie: name = kick , while action-instance-name = kick2342
		actionElement.SetAttribute("name", "move");
		actionElement.SetAttribute("action-instance-name", "move" + (++_moveActionCount));
		actionElement.SetAttribute("result-state", "true"); //successful or failed
		
		actionElement.SetAttribute("target", obj.GetInstanceID().ToString());

		string targetType = obj.tag;
		if(targetType == "OCA" || targetType == "Player")// it's an avatar
		{
			agentSignal.SetAttribute("type", OCEmbodimentXMLTags.AVATAR_OBJECT_TYPE);
			actionElement.SetAttribute("target-type", OCEmbodimentXMLTags.AVATAR_OBJECT_TYPE);
		} else// it's an object
		{
			agentSignal.SetAttribute("type", OCEmbodimentXMLTags.ORDINARY_OBJECT_TYPE);
			actionElement.SetAttribute("target-type", OCEmbodimentXMLTags.ORDINARY_OBJECT_TYPE);
		}
	
		XmlElement paramOld = (XmlElement)actionElement.AppendChild(doc.CreateElement("param"));
		paramOld.SetAttribute("name", "startPosition");
		XmlElement paramNew = (XmlElement)actionElement.AppendChild(doc.CreateElement("param"));
		paramNew.SetAttribute("name", "endPosition");
		
		paramOld.SetAttribute("type", "vector");
		XmlElement oldVectorElement = (XmlElement)paramOld.AppendChild(doc.CreateElement(OCEmbodimentXMLTags.VECTOR_ELEMENT));
		oldVectorElement.SetAttribute(OCEmbodimentXMLTags.X_ATTRIBUTE, startPos.x.ToString());
		oldVectorElement.SetAttribute(OCEmbodimentXMLTags.Y_ATTRIBUTE, startPos.y.ToString());
		oldVectorElement.SetAttribute(OCEmbodimentXMLTags.Z_ATTRIBUTE, startPos.z.ToString());
		
		paramNew.SetAttribute("type", "vector");
		XmlElement newVectorElement = (XmlElement)paramNew.AppendChild(doc.CreateElement(OCEmbodimentXMLTags.VECTOR_ELEMENT));
		newVectorElement.SetAttribute(OCEmbodimentXMLTags.X_ATTRIBUTE, endPos.x.ToString());
		newVectorElement.SetAttribute(OCEmbodimentXMLTags.Y_ATTRIBUTE, endPos.y.ToString());
		newVectorElement.SetAttribute(OCEmbodimentXMLTags.Z_ATTRIBUTE, endPos.z.ToString());
		
		OCMessage message = OCMessage.CreateMessage(_ID, _brainID, OCMessage.MessageType.STRING, BeautifyXmlText(doc));
        
		OCLogger.Debugging("sending move action result: \n" + BeautifyXmlText(doc));
        
		lock(_messageSendingLock)
		{
			_messagesToSend.Add(message);
		}
	}
	// we handle object state change as an "stateChange" action, and send it to the opencog via "agent-signal"
	// it will be processed in opencog the same as handleOtherAgentActionResult
	public void HandleObjectStateChange(UnityEngine.GameObject obj, string stateName, string valueType, System.Object oldValue, System.Object newValue, string blockId = "")
	{
		if(obj == GameObject.FindGameObjectWithTag("OCAGI"))
		{
			return;
		}
		
		string timestamp = GetCurrentTimestamp();
		XmlDocument doc = new XmlDocument();
		XmlElement root = MakeXMLElementRoot(doc);
		
		string id;
		if(blockId != "")
		{
			id = blockId;
		} else
		{
			id = obj.GetInstanceID().ToString();
		}
			
		string targetType;
		if(blockId != "")
		{
			targetType = OCEmbodimentXMLTags.ORDINARY_OBJECT_TYPE;
		} else
		{
			targetType = obj.tag;
		}
		
		XmlElement agentSignal = (XmlElement)root.AppendChild(doc.CreateElement("agent-signal"));
		agentSignal.SetAttribute("id", id);
    
		agentSignal.SetAttribute("timestamp", timestamp);
		XmlElement actionElement = (XmlElement)agentSignal.AppendChild(doc.CreateElement(OCEmbodimentXMLTags.ACTION_ELEMENT));
        
		// note that the name and the action-instance-name are different
		// ie: name = kick , while action-instance-name = kick2342
		actionElement.SetAttribute("name", "stateChange");
		actionElement.SetAttribute("action-instance-name", "stateChange" + (++_stateChangeActionCount).ToString());

		actionElement.SetAttribute("result-state", "true"); 
		
		actionElement.SetAttribute("target", id);
		
		
		if(targetType == "OCA" || targetType == "Player")// it's an avatar
		{
			agentSignal.SetAttribute("type", OCEmbodimentXMLTags.AVATAR_OBJECT_TYPE);
			actionElement.SetAttribute("target-type", OCEmbodimentXMLTags.AVATAR_OBJECT_TYPE);
		} else // it's an object
		{
			agentSignal.SetAttribute("type", OCEmbodimentXMLTags.ORDINARY_OBJECT_TYPE);
			actionElement.SetAttribute("target-type", OCEmbodimentXMLTags.ORDINARY_OBJECT_TYPE);
		}
			
		XmlElement paramStateName = (XmlElement)actionElement.AppendChild(doc.CreateElement("param"));
		paramStateName.SetAttribute("name", "stateName");
		paramStateName.SetAttribute("type", "string");
		paramStateName.SetAttribute("value", stateName);

		XmlElement paramOld = (XmlElement)actionElement.AppendChild(doc.CreateElement("param"));
		paramOld.SetAttribute("name", "OldValue");
		XmlElement paramNew = (XmlElement)actionElement.AppendChild(doc.CreateElement("param"));
		paramNew.SetAttribute("name", "NewValue");
		
				
		if(valueType == "System.Int32") // it's a int
		{
			paramOld.SetAttribute("type", "int");
			paramOld.SetAttribute("value", oldValue.ToString());
			
			paramNew.SetAttribute("type", "int");
			paramNew.SetAttribute("value", newValue.ToString());
		} else if(valueType == "System.Single") // it's a float
		{
			paramOld.SetAttribute("type", "float");
			paramOld.SetAttribute("value", oldValue.ToString());
			
			paramNew.SetAttribute("type", "float");
			paramNew.SetAttribute("value", newValue.ToString());
		} else if(valueType == "System.Boolean") // it's a bool
		{
			paramOld.SetAttribute("type", "boolean");
			paramOld.SetAttribute("value", oldValue.ToString().ToLower());
			
			paramNew.SetAttribute("type", "boolean");
			paramNew.SetAttribute("value", newValue.ToString().ToLower());
		} else if(valueType == "System.String")// it's a string
		{
			paramOld.SetAttribute("type", "string");
			paramOld.SetAttribute("value", oldValue as string);
			
			paramNew.SetAttribute("type", "string");
			paramNew.SetAttribute("value", newValue as string);
		} else if((valueType == "UnityEngine.GameObject") || (valueType == "Avatar"))
		{
			paramOld.SetAttribute("type", "entity");
			XmlElement oldEntityElement = (XmlElement)paramOld.AppendChild(doc.CreateElement(OCEmbodimentXMLTags.ENTITY_ELEMENT));
			MakeEntityElement(oldValue as UnityEngine.GameObject, oldEntityElement);
			
			paramNew.SetAttribute("type", "entity");
			XmlElement newEntityElement = (XmlElement)paramNew.AppendChild(doc.CreateElement(OCEmbodimentXMLTags.ENTITY_ELEMENT));
			MakeEntityElement(newValue as UnityEngine.GameObject, newEntityElement);
		} else if(valueType == "UnityEngine.Vector3") // it's an vector
		{   
			paramOld.SetAttribute("type", "vector");
			UnityEngine.Vector3 vec = (UnityEngine.Vector3)oldValue;
			XmlElement oldVectorElement = (XmlElement)paramOld.AppendChild(doc.CreateElement(OCEmbodimentXMLTags.VECTOR_ELEMENT));
			oldVectorElement.SetAttribute(OCEmbodimentXMLTags.X_ATTRIBUTE, vec.x.ToString());
			oldVectorElement.SetAttribute(OCEmbodimentXMLTags.Y_ATTRIBUTE, vec.y.ToString());
			oldVectorElement.SetAttribute(OCEmbodimentXMLTags.Z_ATTRIBUTE, vec.z.ToString());
			
			paramNew.SetAttribute("type", "vector");
			vec = (UnityEngine.Vector3)newValue;
			XmlElement newVectorElement = (XmlElement)paramNew.AppendChild(doc.CreateElement(OCEmbodimentXMLTags.VECTOR_ELEMENT));
			newVectorElement.SetAttribute(OCEmbodimentXMLTags.X_ATTRIBUTE, vec.x.ToString());
			newVectorElement.SetAttribute(OCEmbodimentXMLTags.Y_ATTRIBUTE, vec.y.ToString());
			newVectorElement.SetAttribute(OCEmbodimentXMLTags.Z_ATTRIBUTE, vec.z.ToString());			

		}
		// todo: we don't have a rotation type
		else
		{
			// we can only process the type define in ActionParamType
			OCLogger.Warn("Unexcepted type: " + valueType + " in OCConnector::handleObjectStateChange!");
		}

		OCMessage message = OCMessage.CreateMessage(_ID, _brainID, OCMessage.MessageType.STRING, BeautifyXmlText(doc));
    
		OCLogger.Debugging("sending state change of " + obj + "\n" + BeautifyXmlText(doc));
    
		lock(_messageSendingLock)
		{
			_messagesToSend.Add(message);
		}		
	}
Esempio n. 26
0
  public static AKRESULT ResetRTPCValue(string in_pszRtpcName, UnityEngine.GameObject in_gameObjectID, int in_uValueChangeDuration, AkCurveInterpolation in_eFadeCurve) {
    
		uint tempin_gameObjectID;
		if ( in_gameObjectID != null )
		{
			tempin_gameObjectID = (uint)in_gameObjectID.GetInstanceID();
			// Note: if AkGameObjectTracker is already attached, the following code will be bypassed.
			if (in_gameObjectID.GetComponent<AkGameObject>() == null)
			{
				in_gameObjectID.AddComponent<AkGameObject>();

				// Note: We have missed AkGameObject.Awake() of this run to register. 
				// So we take over its work by inlining it here.
				AkSoundEngine.RegisterGameObj(in_gameObjectID, in_gameObjectID.name);
			
				//Set the original position
				AkSoundEngine.SetObjectPosition(
		            in_gameObjectID, 
		            in_gameObjectID.transform.position.x, 
		            in_gameObjectID.transform.position.y, 
		            in_gameObjectID.transform.position.z, 
		            in_gameObjectID.transform.forward.x,
		            in_gameObjectID.transform.forward.y, 
		            in_gameObjectID.transform.forward.z
		        	);
			}
		}
		else
		{
			tempin_gameObjectID = unchecked((uint)-1);
		}
		
		
    {
      AKRESULT ret = (AKRESULT)AkSoundEnginePINVOKE.CSharp_ResetRTPCValue__SWIG_4(in_pszRtpcName, tempin_gameObjectID, in_uValueChangeDuration, (int)in_eFadeCurve);

      return ret;
    }
  }
	private void MakeEntityElement(UnityEngine.GameObject obj, XmlElement entityElement)
	{

		if(obj == null)
		{
			entityElement.SetAttribute(OCEmbodimentXMLTags.ID_ATTRIBUTE, "null");
			entityElement.SetAttribute(OCEmbodimentXMLTags.TYPE_ATTRIBUTE, OCEmbodimentXMLTags.UNKNOWN_OBJECT_TYPE);
		} else
		{
			string targetType = obj.tag;
			if(targetType == "OCA" || targetType == "Player")// it's an avatar
			{
				entityElement.SetAttribute(OCEmbodimentXMLTags.ID_ATTRIBUTE, obj.GetInstanceID().ToString());
				entityElement.SetAttribute(OCEmbodimentXMLTags.TYPE_ATTRIBUTE, OCEmbodimentXMLTags.AVATAR_OBJECT_TYPE);
			} else // it's an object
			{
				entityElement.SetAttribute(OCEmbodimentXMLTags.ID_ATTRIBUTE, obj.GetInstanceID().ToString());
				entityElement.SetAttribute(OCEmbodimentXMLTags.TYPE_ATTRIBUTE, OCEmbodimentXMLTags.ORDINARY_OBJECT_TYPE);
			}
		}
	}
Esempio n. 28
0
  public static AKRESULT GetSwitch(string in_pstrSwitchGroupName, UnityEngine.GameObject in_GameObj, out uint out_rSwitchState) {
    
		uint tempin_GameObj;
		if ( in_GameObj != null )
		{
			tempin_GameObj = (uint)in_GameObj.GetInstanceID();
			// Note: if AkGameObjectTracker is already attached, the following code will be bypassed.
			if (in_GameObj.GetComponent<AkGameObject>() == null)
			{
				in_GameObj.AddComponent<AkGameObject>();

				// Note: We have missed AkGameObject.Awake() of this run to register. 
				// So we take over its work by inlining it here.
				AkSoundEngine.RegisterGameObj(in_GameObj, in_GameObj.name);
			
				//Set the original position
				AkSoundEngine.SetObjectPosition(
		            in_GameObj, 
		            in_GameObj.transform.position.x, 
		            in_GameObj.transform.position.y, 
		            in_GameObj.transform.position.z, 
		            in_GameObj.transform.forward.x,
		            in_GameObj.transform.forward.y, 
		            in_GameObj.transform.forward.z
		        	);
			}
		}
		else
		{
			tempin_GameObj = unchecked((uint)-1);
		}
		
		
    {
      AKRESULT ret = (AKRESULT)AkSoundEnginePINVOKE.CSharp_GetSwitch__SWIG_1(in_pstrSwitchGroupName, tempin_GameObj, out out_rSwitchState);

      return ret;
    }
  }
	// Send all the existing states of object to opencog when the robot is loaded 
	// it will be processed in opencog the same as opencog::pai::InitStateInfo()
	public void SendExistingStates(UnityEngine.GameObject obj, string stateName, string valueType, System.Object stateValue)
	{
		string timestamp = GetCurrentTimestamp();
		System.Diagnostics.Debug.Assert(obj != null && stateName != "" && valueType != "");
		XmlDocument doc = new XmlDocument();
		XmlElement root = MakeXMLElementRoot(doc);
		
		string id = obj.GetInstanceID().ToString();
				
		XmlElement StateSignal = (XmlElement)root.AppendChild(doc.CreateElement("state-info"));
		StateSignal.SetAttribute("object-id", id);

		if(obj.tag == "OCA" || obj.tag == "Player")
		{// it's an avatar
			StateSignal.SetAttribute("object-type", OCEmbodimentXMLTags.AVATAR_OBJECT_TYPE);
		} else
		{ // it's an object
			StateSignal.SetAttribute("object-type", OCEmbodimentXMLTags.ORDINARY_OBJECT_TYPE);
		}

		StateSignal.SetAttribute("state-name", stateName);
		StateSignal.SetAttribute("timestamp", timestamp);
		
		XmlElement valueElement = (XmlElement)StateSignal.AppendChild(doc.CreateElement("state-value"));
						
		if(valueType == "System.Int32") // it's a int
		{
			valueElement.SetAttribute("type", "int");
			valueElement.SetAttribute("value", stateValue.ToString());
		} else if(valueType == "System.Single") // it's a float
		{
			valueElement.SetAttribute("type", "float");
			valueElement.SetAttribute("value", stateValue.ToString());			
		} else if(valueType == "System.Boolean") // it's a bool
		{
			valueElement.SetAttribute("type", "boolean");
			valueElement.SetAttribute("value", stateValue.ToString().ToLower());
		} else if(valueType == "System.String")// it's a string
		{
			valueElement.SetAttribute("type", "string");
			valueElement.SetAttribute("value", stateValue as string);
			
		} else if(valueType == "UnityEngine.GameObject")
		{
			valueElement.SetAttribute("type", "entity");
			XmlElement entityElement = (XmlElement)valueElement.AppendChild(doc.CreateElement(OCEmbodimentXMLTags.ENTITY_ELEMENT));
			MakeEntityElement(stateValue as UnityEngine.GameObject, entityElement);
		} else if(valueType == "UnityEngine.Vector3") // it's an vector
		{   
			valueElement.SetAttribute("type", "vector");
			UnityEngine.Vector3 vec = (UnityEngine.Vector3)stateValue;
			XmlElement vectorElement = (XmlElement)valueElement.AppendChild(doc.CreateElement(OCEmbodimentXMLTags.VECTOR_ELEMENT));
			vectorElement.SetAttribute(OCEmbodimentXMLTags.X_ATTRIBUTE, vec.x.ToString());
			vectorElement.SetAttribute(OCEmbodimentXMLTags.Y_ATTRIBUTE, vec.y.ToString());
			vectorElement.SetAttribute(OCEmbodimentXMLTags.Z_ATTRIBUTE, vec.z.ToString());
		}
		
		// todo: we don't have a rotation type
		else
		{
			// we can only process the type define in ActionParamType
			OCLogger.Warn("Unexcepted type: " + valueType + " in OCConnector::handleObjectStateChange!");
			return;
		}

		OCMessage message = OCMessage.CreateMessage(_ID, _brainID, OCMessage.MessageType.STRING, BeautifyXmlText(doc));
    
		OCLogger.Debugging("sending state change of " + obj + "\n" + BeautifyXmlText(doc));
    
		lock(_messageSendingLock)
		{
			_messagesToSend.Add(message);
		}		
	}	
Esempio n. 30
0
  public static AKRESULT GetGameObjectAuxSendValues(UnityEngine.GameObject in_gameObjectID, AkAuxSendArray out_paAuxSendValues, ref uint io_ruNumSendValues) {
    
		uint tempin_gameObjectID;
		if ( in_gameObjectID != null )
		{
			tempin_gameObjectID = (uint)in_gameObjectID.GetInstanceID();
			// Note: if AkGameObjectTracker is already attached, the following code will be bypassed.
			if (in_gameObjectID.GetComponent<AkGameObject>() == null)
			{
				in_gameObjectID.AddComponent<AkGameObject>();

				// Note: We have missed AkGameObject.Awake() of this run to register. 
				// So we take over its work by inlining it here.
				AkSoundEngine.RegisterGameObj(in_gameObjectID, in_gameObjectID.name);
			
				//Set the original position
				AkSoundEngine.SetObjectPosition(
		            in_gameObjectID, 
		            in_gameObjectID.transform.position.x, 
		            in_gameObjectID.transform.position.y, 
		            in_gameObjectID.transform.position.z, 
		            in_gameObjectID.transform.forward.x,
		            in_gameObjectID.transform.forward.y, 
		            in_gameObjectID.transform.forward.z
		        	);
			}
		}
		else
		{
			tempin_gameObjectID = unchecked((uint)-1);
		}
		
		
    {
      AKRESULT ret = (AKRESULT)AkSoundEnginePINVOKE.CSharp_GetGameObjectAuxSendValues(tempin_gameObjectID, out_paAuxSendValues.m_Buffer, ref io_ruNumSendValues);

      return ret;
    }
  }