Beispiel #1
0
        public void Push(UnityEngine.GameObject prefab)
        {
            if (prefab == null)
            {
                throw new Exception("this gameobect is null");
            }

            PrefabPoolEntity pool     = null;
            string           poolName = string.Empty;

            prefabIdDic.TryGetValue(prefab.GetInstanceID(), out poolName);

            if (string.IsNullOrEmpty(poolName))
            {
                GameEntry.Debug.LogError($"not this {prefab.GetInstanceID().ToString()} instanceId prefab");
                return;
            }

            poolDic.TryGetValue(poolName, out pool);
            if (pool == null)
            {
                GameEntry.Debug.Log($"push this {poolName} pool,pool is not initialize ");
                pool       = new PrefabPoolEntity();
                pool.Stack = new Stack <UnityEngine.GameObject>();
            }
            pool.Stack.Push(prefab);

            GameEntry.Debug.Log($"{poolName}pool size is {pool.Stack.Count.ToString()}");
        }
Beispiel #2
0
        public bool IsGameObjectGroupVailed(int groupId, UnityEngine.GameObject target)
        {
            AKAudioEntry.AudioAssert(target != null);
            int instanceId = target.GetInstanceID();

            return(typeSwitch_GameObjHash_Datas.ContainsKey(instanceId));
        }
Beispiel #3
0
        /// <summary>
        /// 中途关闭一组补间动画
        /// </summary>
        /// <param name="go">游戏对象</param>
        public void Kill(UnityEngine.GameObject go)
        {
            int          groupID = go.GetInstanceID();
            TweenWrapper wrapper = GetTweenWrapper(groupID);

            if (wrapper != null)
            {
                wrapper.TweenRoot.Kill();
            }
        }
Beispiel #4
0
        /// <summary>
        /// 播放一个补间动画
        /// </summary>
        /// <param name="tweenRoot">补间根节点</param>
        /// <param name="go">游戏对象</param>
        /// <returns>补间动画唯一ID</returns>
        public long Play(ITweenNode tweenRoot, UnityEngine.GameObject go = null)
        {
            int groupID = 0;

            if (go != null)
            {
                groupID = go.GetInstanceID();
            }
            return(CreateTween(tweenRoot, go, groupID));
        }
 public void RegisterGameObject(UnityEngine.GameObject objectToRegister)
 {
     if (objectToRegister != null)
     {
         _gameObjectRegistry.Add(objectToRegister.GetInstanceID(), objectToRegister);
     }
     else
     {
         UnityEngine.Debug.Log("OCGameObjectRegistry::RegisterGameObject: objectToRegister == null");
     }
 }
Beispiel #6
0
        public AKRESULT VarySwitchState(int groupId, UnityEngine.GameObject target, string state = "")
        {
            AKAudioEntry.AudioAssert(target != null);
            int           instanceId = target.GetInstanceID();
            AKSwitchGroup group;
            AKRESULT      ret;

            if (typeSwitch_GameObjHash_Datas.TryGetValue(instanceId, out group))
            {
                if (string.IsNullOrEmpty(state))
                {
                    ret = AkSoundEngine.SetSwitch(group.GetGroupName(), group.GetDefaultState(), target);
                }
                else if (!group.CanVaryState(state))
                {
                    return(AKRESULT.AK_InvalidStateGroupElement);
                }
                else
                {
                    ret = AkSoundEngine.SetSwitch(group.GetGroupName(), state, target);
                }
            }
            else
            {
                group = AKSwitchGroup.Allocate(groupId, target);
                if (group.CanVaryState(state))
                {
                    ret = AkSoundEngine.SetSwitch(group.GetGroupName(), state, target);
                }
                else
                {
                    ret = AkSoundEngine.SetSwitch(group.GetGroupName(), group.GetDefaultState(), target);
                }
                typeSwitch_GameObjHash_Datas.Add(instanceId, group);
            }
            VaryGroupIfSucess(group, ret, state);
            return(ret);
        }
 private static ulong InternalGameObjectHash(UnityEngine.GameObject gameObject)
 {
     return(gameObject == null ? AK_INVALID_GAME_OBJECT : (ulong)gameObject.GetInstanceID());
 }
Beispiel #8
0
        private bool CheckCondition(UnityEngine.GameObject objectToCheck, System.Collections.Generic.List <string> listOfConditions)
        {
            bool valid = true;

            foreach (var condition in listOfConditions)
            {
                var option = CheckOption(condition);
                switch (option)
                {
                case 1:    //name
                    var name = condition;
                    valid = objectToCheck.name.Equals(name);
                    break;

                case 2:    //tag
                    var tagName = condition.Substring(5, condition.Length - 5);
                    valid = objectToCheck.CompareTag(tagName);
                    break;

                case 3:    //layer
                    var layerName = condition.Substring(7, condition.Length - 7);
                    int layerId   = UnityEngine.LayerMask.NameToLayer(layerName);
                    valid = objectToCheck.layer.Equals(layerId);
                    break;

                case 4:    //component
                    var componentName = condition.Substring(11, condition.Length - 11);
                    var list          = objectToCheck.GetComponents(typeof(UnityEngine.Component));
                    valid = false;

                    for (int i = 0; i < list.Length; i++)
                    {
                        if (componentName.Equals(list[i].GetType().Name))
                        {
                            valid = true;
                            break;
                        }
                    }
                    break;

                case 5:    //id
                    var id = System.Convert.ToInt32(condition.Substring(4, condition.Length - 4));
                    valid = (objectToCheck.GetInstanceID() == id);
                    break;

                case 6:    //contains
                    var substring      = condition.Substring(9, condition.Length - 10);
                    var splitedValue   = substring.Split(',');
                    var selector       = splitedValue[0];
                    var value          = splitedValue[1];
                    var optionContains = CheckOption(selector);
                    switch (optionContains)
                    {
                    case 2:
                        valid = objectToCheck.tag.Contains(value);
                        break;

                    case 3:
                        var layerNm = UnityEngine.LayerMask.LayerToName(objectToCheck.layer);
                        valid = layerNm.Contains(value);
                        break;

                    case 4:
                        componentName = value;
                        list          = objectToCheck.GetComponents(typeof(UnityEngine.Component));
                        valid         = false;

                        for (int i = 0; i < list.Length; i++)
                        {
                            if (componentName.Contains(list[i].GetType().Name))
                            {
                                valid = true;
                                break;
                            }
                        }
                        break;

                    case 5:
                        var stringId = objectToCheck.GetInstanceID().ToString();
                        valid = stringId.Contains(value);
                        break;

                    case 8:
                        valid = objectToCheck.name.Contains(value);
                        break;

                    default:
                        throw new System.Exception("No such selector is implemented");
                    }
                    break;
                }
                if (!valid)
                {
                    break;
                }
            }
            return(valid);
        }
        public OCObjectMapInfo(UnityEngine.GameObject gameObject)
        {
            UnityEngine.Debug.Log("OCObjectMapInfo::OCObjectMapInfo, passed object is of type: " + gameObject.GetType().ToString() + ", and name " + gameObject.name);

            _id = gameObject.GetInstanceID().ToString();

//			// Get id of a game object
//			_id = gameObject.GetInstanceID ().ToString ();
            // Get name
            _name = gameObject.name;
            // TODO: By default, we are using object type.
            _type = OCEmbodimentXMLTags.ORDINARY_OBJECT_TYPE;

            // Convert from unity coordinate to OAC coordinate.

            this.position = Utility.VectorUtil.ConvertToOpenCogCoord(gameObject.transform.position);
            // Get rotation
            _rotation = new Utility.Rotation(gameObject.transform.rotation);
            // Calculate the velocity later
            _velocity = UnityEngine.Vector3.zero;

            // Get size
            if (gameObject.collider != null)
            {
                // Get size information from collider.
                _width  = gameObject.collider.bounds.size.z;
                _height = gameObject.collider.bounds.size.y;
                _length = gameObject.collider.bounds.size.x;
            }
            else
            {
                OCLogger.Warn("No collider for gameobject " + gameObject.name + ", assuming a point.");

                // Set default value of the size.
                _width  = 0.1f;
                _height = 0.1f;
                _length = 0.1f;
            }

            if (gameObject.tag == "OCAGI")
            {
                // This is an OC avatar, we will use the brain id instead of unity id.
                OCConnectorSingleton connector = OCConnectorSingleton.Instance;

                if (connector != null)
                {
                    _id   = connector.BrainID;
                    _type = OCEmbodimentXMLTags.PET_OBJECT_TYPE;
                }

                UnityEngine.Debug.Log("Just made an OCObjectMapInfo stating the AGI is at [" + this.position.x + ", " + this.position.y + ", " + this.position.z + "]");
            }
            else if (gameObject.tag == "OCNPC")
            {
                // This is a human player avatar.
                _type   = OCEmbodimentXMLTags.AVATAR_OBJECT_TYPE;
                _length = OCObjectMapInfo.DEFAULT_AVATAR_LENGTH;
                _width  = OCObjectMapInfo.DEFAULT_AVATAR_WIDTH;
                _height = OCObjectMapInfo.DEFAULT_AVATAR_HEIGHT;
            }

            if (gameObject.tag == "OCNPC" || gameObject.tag == "OCAGI" || gameObject.tag == "Player")
            {
                if (_height > 1.1f)                 // just to make sure that the center point of the character will not be in the block where the feet are
                {
                    this.position = new UnityEngine.Vector3(this.position.x, this.position.y, this.position.z + 1.0f);
                }
            }


            if (gameObject.name == "Hearth")
            {
                this.AddProperty("petHome", "TRUE", System.Type.GetType("System.Boolean"));
            }

            // Get weight
            if (gameObject.rigidbody != null)
            {
                _weight = gameObject.rigidbody.mass;
            }
            else
            {
                _weight = 0.0f;
            }

            if (gameObject.GetComponent <OpenCog.Extensions.OCConsumableData>() != null)
            {
                UnityEngine.Debug.Log("Adding edible and foodbowl tags to '" + gameObject.name + "' with ID " + gameObject.GetInstanceID());
                this.AddProperty("edible", "TRUE", System.Type.GetType("System.Boolean"));
                this.AddProperty("pickupable", "TRUE", System.Type.GetType("System.Boolean"));
                this.AddProperty("holder", "none", System.Type.GetType("System.String"));
            }

            // Get a property manager instance
            // TODO: may need to re-enable this for other object types.
//			OCPropertyManager manager = gameObject.GetComponent<OCPropertyManager> () as OCPropertyManager;
//			if (manager != null) {
//				// Copy all OC properties from the manager, if any.
//				foreach (OpenCog.Serialization.OCPropertyField ocp in manager.propertyList) {
//					this.AddProperty (ocp.Key, ocp.value, ocp.valueType);
//				}
//			}

            this.AddProperty("visibility-status", "visible", System.Type.GetType("System.String"));
            this.AddProperty("detector", "true", System.Type.GetType("System.Boolean"));

            string gameObjectName = gameObject.name;

            if (gameObjectName.Contains("("))
            {
                gameObjectName = gameObjectName.Remove(gameObjectName.IndexOf('('));
            }



            // For Einstein puzzle
            if (gameObject.name.Contains("_man"))
            {
                _id = _name;
                this.AddProperty("class", "people", System.Type.GetType("System.String"));
            }
            else
            {
                this.AddProperty("class", gameObjectName, System.Type.GetType("System.String"));
            }
        }