当前位置: 首页>>代码示例>>C#>>正文


C# GameObject.ToString方法代码示例

本文整理汇总了C#中UnityEngine.GameObject.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# GameObject.ToString方法的具体用法?C# GameObject.ToString怎么用?C# GameObject.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在UnityEngine.GameObject的用法示例。


在下文中一共展示了GameObject.ToString方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: RecycleAsset

		public void RecycleAsset (GameObject asset)
		{
			AssetInfo assetInfo = asset.GetComponent<AssetInfo>();

			if (assetInfo != null)
			{
				AssetPool pool = null;
				assetPoolDic.TryGetValue(assetInfo.type, out pool);

				if (pool != null)
				{
					pool.Add(assetInfo);
				}
				else
				{
					Debug.LogError("Asset can't find its pool: " + asset.ToString() + " of type: " + assetInfo.type);
				}
			}
			else
			{
				Debug.LogError("Wrong asset to recycle: " + asset.ToString());
			}
		}
开发者ID:sigmadruid,项目名称:NewMaze,代码行数:23,代码来源:AssetManager.cs

示例2: GetAssemblyComponent

        /// <summary>
        /// Retrieves a component from the current GameObject which matches with the method inparameter.
        /// The method tries to find out which of the objects components the method belongs to and returns it.
        /// </summary>
        /// <param name="currentObject">The object the method is connected to.</param>
        /// <param name="methodName">The name of the method which needs to be found and invoked.</param>
        /// <param name="inparameters">Optional inparameters for the method.</param>
        private Component GetAssemblyComponent(GameObject currentObject, string methodName, object[] inparameters)
        {
            Component[] objectComponentList = currentObject.GetComponents(typeof(MonoBehaviour));
            int componentObjectCount = objectComponentList.Length;

            Assembly[] referencedAssemblies = System.AppDomain.CurrentDomain.GetAssemblies();
            int referenceAssemblyObjectCount = referencedAssemblies.Length;

            for (int i = 0; i < componentObjectCount; ++i)
            {
                if (objectComponentList[i] == null)
                    continue;

                System.Type componentType = objectComponentList[i].GetType();
                string componentNameString = componentType.ToString();

                for (int assemblyObjectIterator = 0; assemblyObjectIterator < referenceAssemblyObjectCount; ++assemblyObjectIterator)
                {
                    System.Type assemblyComponentType = referencedAssemblies[assemblyObjectIterator].GetType(componentNameString);
                    if (assemblyComponentType != null && methodName != string.Empty)
                    {
                        MethodInfo foundMethodObject = null;
                        try
                        {
                            foundMethodObject = assemblyComponentType.GetMethod(methodName);
                        }
                        catch
                        {
                            Debug.LogWarning(this + " - Multiple methods with the same name (" + methodName + ") was found. The method can not choose which of these methods to get. Please recheck the mentod names.");
                        }

                        if (foundMethodObject != null)
                            return objectComponentList[i];
                    }
                }
            }

            StringBuilder errorString = new StringBuilder();
            errorString.Append(this.ToString());
            errorString.Append(" - ");
            errorString.Append(this.gameObject.ToString());
            errorString.Append(" - No valid component was found for '");
            errorString.Append(currentObject.ToString());
            errorString.Append("' with the method '");
            errorString.Append(methodName.ToString());
            errorString.Append("'.");
            errorString.Append("Make sure the method in the affect script is set as public, and not private.");
            Debug.LogError(errorString.ToString());
            return null;
        }
开发者ID:DevMikaelNilsson,项目名称:mnUtilities,代码行数:57,代码来源:InvokeMethod.cs

示例3: ReturnObjectToObjectPool

        /// <summary>
        /// Returns and adds a object to the existing object pool.
        /// </summary>
        /// <param name="objectType">The search type you want to search for existing object pool.</param>
        /// <param name="currentGameObject">GameObject to search for.</param>
        /// <returns>True if the object was successfully added to the object pool. False otherwise.</returns>
        public bool ReturnObjectToObjectPool(GetObjectByType objectType, GameObject currentGameObject)
        {
            if (currentGameObject == null)
                return false;

            int internalListCount	= ObjectPoolList.Count;
            int index				= 0;
            while(index < internalListCount)
            {
                string currentObjectTypeString = string.Empty;
                string returningObjectString = string.Empty;

                if(ObjectPoolList[index] != null)
                {
                    switch (objectType)
                    {
                    case GetObjectByType.Tag:
                        currentObjectTypeString = ObjectPoolList[index].tag;
                        returningObjectString = currentGameObject.tag;
                        break;
                    case GetObjectByType.Name:
                        currentObjectTypeString = ObjectPoolList[index].name;
                        returningObjectString = currentGameObject.name;
                        break;
                    case GetObjectByType.GameObject:
                        currentObjectTypeString = ObjectPoolList[index].ToString();
                        returningObjectString = currentGameObject.ToString();
                        break;
                    default:
                        return false;
                    }

                    if (string.Equals(currentObjectTypeString, returningObjectString) == true)
                    {
                        if(currentGameObject != null)
                        {
                            DeactivateObject(currentGameObject);
                            m_internalObjectPool[index].Add(currentGameObject);
                            return true;
                        }
                    }
                }
                index += 1;
            }

            return false;
        }
开发者ID:DevMikaelNilsson,项目名称:mnUtilities,代码行数:53,代码来源:ObjectPoolManager.cs


注:本文中的UnityEngine.GameObject.ToString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。