コード例 #1
0
 public List<MethodInfo> GetBooleanMethodsFrom(GameObject gameObject)
 {
     List<MethodInfo> booleanMethods = new List<MethodInfo> ();
     //GameObject boolean methods
     foreach(MethodInfo mo in gameObject.GetType().GetMethods(BindingFlags.Instance | BindingFlags.Public)) {
         if(mo.GetParameters().Length==0
            && mo.ReturnType == typeof(Boolean)) {
             booleanMethods.Add(mo);
         }
     }
     //Component of gameObject boolean methods
     Component[] comps = gameObject.GetComponents<Component>();
     foreach (Component comp in comps) {
         if(comp==null)
             continue;
         MethodInfo[] methods = comp.GetType ().GetMethods (BindingFlags.Instance | BindingFlags.Public);
         foreach(MethodInfo mi in methods) {
             if(mi.GetParameters().Length==0
                && mi.ReturnType == typeof(Boolean))
                 booleanMethods.Add (mi);
         }
     }
     return booleanMethods;
 }
コード例 #2
0
ファイル: SceneBuilder.cs プロジェクト: BabylonJS/Babylon.js
 private object GetGamePropertyValue(GameObject game)
 {
     if (game == null) return null;
     Dictionary<string, object> objectInfo = new Dictionary<string, object>();
     objectInfo.Add("type", game.GetType().FullName);
     objectInfo.Add("id", GetID(game));
     objectInfo.Add("tag", game.tag);
     objectInfo.Add("name", game.name);
     objectInfo.Add("layer", game.layer);
     objectInfo.Add("isStatic", game.isStatic);
     objectInfo.Add("hideFlags", game.hideFlags.ToString());
     return objectInfo;
 }
コード例 #3
0
		private static Type GetPropertyTypeFromString(GameObject gameObj, string propertyPath)
		{
			if (propertyPath == "")
				return gameObj.GetType();

			var propsQueue = new Queue<string>(propertyPath.Split('.').Where(s => !string.IsNullOrEmpty(s)));

			if (propsQueue == null) throw new ArgumentException("Incorrent property path");

			Type result;
			if (char.IsLower(propsQueue.Peek()[0]))
			{
				result = gameObj.GetType();
			}
			else
			{
				var component = gameObj.GetComponent(propsQueue.Dequeue());

				if (component == null) throw new ArgumentException("Incorrent property path");

				result = component.GetType();
			}
			while (propsQueue.Count != 0)
			{
				var nameToFind = propsQueue.Dequeue();

				var property = result.GetProperty(nameToFind);
				if (property != null)
				{
					result = property.PropertyType;
				}
				else
				{
					var field = result.GetField(nameToFind);
					if (field == null) throw new ArgumentException("Incorrent property path");
					result = field.FieldType;
				}
			}
			return result;
		}
コード例 #4
0
        public OCObjectMapInfo(UnityEngine.GameObject gameObject)
        {
            System.Console.WriteLine(OCLogSymbol.RUNNING + "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 [UNTESTED]: 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
            {
                Debug.LogWarning(OCLogSymbol.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;
                }

                System.Console.WriteLine(OCLogSymbol.RUNNING + "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)
            {
                System.Console.WriteLine(OCLogSymbol.RUNNING + "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 [BLOCKED]: 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"));
            }
        }
コード例 #5
0
        /// <summary>
        /// Setup game manager, links the components, enumarates racers and helps everything goes well on race
        /// </summary>
        private void InitRace()
        {
            if (RaceLaps < 1)
            {
                RaceLaps = 1;
            }
            if (RacePlayers < 1)
            {
                RacePlayers = 1;
            }

            //Reach to UI, we'll send countdown and show/hide countdown window
            GameUIComponent = (IRGKUI)transform.GetComponent(typeof(IRGKUI));

            //Reach GameAudio for playing stuff
            GameAudioComponent = (Race_Audio)transform.GetComponent(typeof(Race_Audio));
            if (GameAudioComponent != null)
            {
                GameAudioComponent.InitAudio();
            }
            else
            {
                Debug.LogWarning("RACING GAME KIT WARNING\r\nRace Audio component not found or disabled! Race Audio will not managed by RaceManager");
            }


            //Determinate GameCamera, this will attached to player car.
            GameObject oRGKCamera = GameObject.Find("_GameCamera");

            if (oRGKCamera != null)
            {
                GameCamereComponent = oRGKCamera.GetComponent(typeof(RacingGameKit.Interfaces.IRGKCamera)) as RacingGameKit.Interfaces.IRGKCamera;
                GameCamereComponent.IsStartupAnimationEnabled = EnableStartupCamera;
            }
            else
            {
                Debug.LogWarning(RGKMessages.GameCameraMissing);
                Debug.DebugBreak();
                return;
            }

            //Create racer names from name array. This is for AI racers
            ListRacerNames = new List <String>(AIRacerNames);

            ///Checkpoint System Enable
            if (CheckPoints == null || CheckPoints.transform.childCount == 0) // If Checkoints Implemented
            {
                Debug.Log(RGKMessages.CheckpointSystemDisabled);
                EnableCheckPointSystem = false;
            }
            else
            {
                EnableCheckPointSystem = true;
                GetFirstCheckPoint();
            }

            //Determinate spawn points.
            if (SpawnPoints != null)
            {
                Transform[] SPItems = GetChildTransforms(SpawnPoints.transform);

                if (GameCamereComponent.TargetObjects == null)
                {
                    GameCamereComponent.TargetObjects = new List <Transform>();
                }

                if (PlayerSpawnPosition > RacePlayers)
                {
                    PlayerSpawnPosition = RacePlayers;
                }

                bool DeployHumanNow     = false;
                bool DeploymentComplete = false;

                for (int i = 0; i < SPItems.GetLength(0); i++)
                {
                    UnityEngine.GameObject iRacer = null;

                    if (HumanRacerPrefab != null && !HumanDeployed && (i + 1 == PlayerSpawnPosition))
                    {
                        DeployHumanNow = true;
                    }
                    else if (AIRacerPrefab.Length > 0)
                    {
                        if (AIRacerPrefab[0] != null)
                        {
                            int AiIndexGoingToSpawn = 0;

                            if (AiSpawnOrder == eAISpawnOrder.Random)
                            {
                                if (AIRacerPrefab.Length > 1)
                                {
                                    if (AiSpawnMode == eAISpawnMode.Random)
                                    {
                                        AiIndexGoingToSpawn = UnityEngine.Random.Range(0, AIRacerPrefab.Length);
                                    }
                                    else if (AiSpawnMode == eAISpawnMode.OneTimeEach)
                                    {
                                        AiIndexGoingToSpawn = FindNextNotSpawnedAiIndex();
                                        if (AiIndexGoingToSpawn != -1)
                                        {
                                            SpawnedAIs.Add(AiIndexGoingToSpawn);
                                            Debug.Log("Spawn No " + AiIndexGoingToSpawn);
                                        }
                                        else
                                        {
                                            if (!HumanDeployed)
                                            {
                                                DeployHumanNow = true;
                                            }
                                            DeploymentComplete = true;
                                        }
                                    }
                                }
                            }
                            else if (AiSpawnOrder == eAISpawnOrder.Order)
                            {
                                AiIndexGoingToSpawn = LastSpawnedAIIndex;
                                LastSpawnedAIIndex += 1;
                                if (LastSpawnedAIIndex > AIRacerPrefab.Length)
                                {
                                    AiIndexGoingToSpawn = -1;
                                    DeploymentComplete  = true;
                                }
                            }


                            if (AiIndexGoingToSpawn != -1)
                            {
                                iRacer = (GameObject)Instantiate(AIRacerPrefab[AiIndexGoingToSpawn], SPItems[i].transform.position, SPItems[i].transform.rotation);
                                iRacer.GetType();//Debug Warning Removal;

                                Transform CameraTargetTransform = ((GameObject)iRacer).transform.FindChild("_CameraTarget");
                                if (CameraTargetTransform == null)
                                {
                                    CameraTargetTransform = ((GameObject)iRacer).transform;
                                }

                                GameCamereComponent.TargetObjects.Add(CameraTargetTransform);
                                ///Target the camera to latest AI
                                if (HumanRacerPrefab == null)
                                {
                                    GameCamereComponent.TargetVehicle = CameraTargetTransform;
                                }
                            }
                        }
                    }

                    if (DeployHumanNow)
                    {
                        iRacer = (GameObject)Instantiate(HumanRacerPrefab, SPItems[i].transform.position, SPItems[i].transform.rotation);

                        Transform CameraTargetTransform = ((GameObject)iRacer).transform.FindChild("_CameraTarget");
                        if (CameraTargetTransform == null)
                        {
                            CameraTargetTransform = ((GameObject)iRacer).transform;
                        }

                        GameCamereComponent.TargetObjects.Add(CameraTargetTransform);
                        GameCamereComponent.TargetVehicle = CameraTargetTransform;
                        HumanDeployed  = true;
                        DeployHumanNow = false;
                    }

                    if (i + 1 == RacePlayers || DeploymentComplete)
                    {
                        break;
                    }
                }
            }
            else
            {
                Debug.LogWarning(RGKMessages.SpawnPointsObjectMissing);
                Debug.DebugBreak();
                return;
            }

            CreateDistanceMeasurementTransforms();
            CurrentCount = TimerCountdownFrom;

            IsRaceReady = true;

            if (RaceStartsOnStartup)
            {
                StartRace();
            }

            if (!StartMusicAfterCountdown)
            {
                if (GameAudioComponent != null)
                {
                    GameAudioComponent.PlayBackgroundMusic(true);
                }
            }
        }
コード例 #6
0
		private void PrintUnityGameObject(GameObject o, IndentedTextWriter writer, Func<GameObject, bool> gameObjectFilter, Func<Component, bool> componentFilter) {
			if (o == null) {
				writer.WriteLine("(null)");
				return;
			}
			
			writer.WriteLine("{0} : {1}", o.GetType(), o.name);
			if (_visited.ContainsKey(o)) {
				writer.Write(" (already dumped)");
				return;
			}
			writer.Indent++;
			writer.WriteLine("Components:");
			writer.Indent++;
			
			_visited[o] = true;
			foreach (var component in o.GetComponents(typeof (Component))) {
				writer.WriteLine("[Component] {0}", component.GetType().Name);
				if (!componentFilter(component)) continue;
				writer.Indent++;
				PrintObjectMembers(writer, component);
				writer.Indent--;
			}
			writer.Indent--;
			writer.WriteLine("Children:");

			var numChildren = o.transform.childCount;
			for (int i = 0; i < numChildren; i++) {
				var child = o.transform.GetChild(i);
				writer.Indent++;
				writer.Write("{0}. [Child] ", i);
				if (gameObjectFilter(child.gameObject)) {
					PrintUnityGameObject(child.gameObject, writer, gameObjectFilter, componentFilter);	
				}
				
				writer.Indent--;
			}
			writer.Indent--;
		}
コード例 #7
0
			public void PrintUnityGameObject(GameObject o, int recursionDepth = 0) {
				if (o == null) {
					_writer.WriteLine("(null)");
					return;
				}
				_writer.Write("{0} : {1}", o.GetType(), o.name);
				if (_visited.ContainsKey(o)) {
					_writer.WriteLine(" (already dumped)");
					return;
				}
				if (recursionDepth >= _parent.MaxRecursionDepth) {
					_writer.WriteLine(" (recursion depth exceeded)");
					return;
				}
				_writer.WriteLine();
				_writer.Indent++;
				_writer.WriteLine($"Parent: {o.transform.parent?.name}");
				_writer.WriteLine("Components:");
				_writer.Indent++;

				_visited[o] = true;
				foreach (var component in o.Components(typeof (Component))) {
					_writer.WriteLine("[Component] {0}", component.GetType().Name);
					if (!_parent.ComponentFilter(component)) continue;
					_writer.Indent++;
					PrintObjectMembers(component);
					_writer.Indent--;
				}
				_writer.Indent--;
				_writer.WriteLine("Children:");

				var numChildren = o.transform.childCount;
				for (int i = 0; i < numChildren; i++) {
					var child = o.transform.GetChild(i);
					_writer.Write("{0}.\t [Child] ", i);
					if (_parent.GameObjectFilter(child.gameObject)) {
						PrintUnityGameObject(child.gameObject, recursionDepth + 1);
					}
				}
				_writer.Indent--;
			}