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


C# PropertyCollection.TryGetValue方法代码示例

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


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

示例1: ApplyCustomProperties

        /// <summary>
        /// Applies to a GameObject any custom property found in PropertyCollection
        /// </summary>
        /// <param name="gameObject">GameObject to apply custom properties to</param>
        /// <param name="properties">PropertyCollection to read custom properties from</param>
        public static void ApplyCustomProperties(GameObject gameObject, PropertyCollection properties)
        {
            // nothing to do here...
            if (gameObject == null || properties == null)
                return;

            // Set a layer number for gameObject
            if (properties.HasProperty(Map.Property_Layer))
                gameObject.layer = properties.GetPropertyAsInt(Map.Property_Layer);

            if (properties.HasProperty(Map.Property_LayerName))
                gameObject.layer = LayerMask.NameToLayer(properties.GetPropertyAsString(Map.Property_LayerName));

            // Add a tag for gameObject
            if (properties.HasProperty(Map.Property_Tag))
                gameObject.tag = properties.GetPropertyAsString(Map.Property_Tag);

            int c = 1;
            // Unity 5 Removed AddComponent("string")...
            #if !UNITY_5
            // Add Components for this gameObject
            while (properties.HasProperty(Map.Property_AddComponent + c))
            {
                try
                {
                    gameObject.AddComponent(properties.GetPropertyAsString(Map.Property_AddComponent + c));

                }
                catch (System.Exception e)
                {
                    Debug.LogError(e);
                }
                c++;
            }
            c = 1;
            #else
            // Add Components for this gameObject
            while (properties.HasProperty(Map.Property_AddComponent + c))
            {
                try
                {
                    //gameObject.AddComponent(System.Type.GetType(properties.GetPropertyAsString(Map.Property_AddComponent + c)));
                    //gameObject.AddComponent(System.Type.GetType("Door")) as Door;

                    if(properties.GetPropertyAsString(Map.Property_AddComponent + c) == "Door"){
                        gameObject.AddComponent<Door>();
                    }else if(properties.GetPropertyAsString(Map.Property_AddComponent + c) == "CollisionLevel"){
                        gameObject.AddComponent<CollisionLevel>();
                    }else if(properties.GetPropertyAsString(Map.Property_AddComponent + c) == "HidePlayer"){
                        gameObject.AddComponent<HidePlayer>();
                    }

                }
                catch (System.Exception e)
                {
                    Debug.LogError(e);
                }
                c++;
            }
            c = 1;

            //Set variables for Component Door
            Door door;
            if(door = gameObject.GetComponent<Door>()){

                Debug.Log("HAS DOOR");

                Property force;

                //Debug.Log(gameObject.name+" FORCE "+force.RawValue.ToString());

                if(properties.TryGetValue(Map.Property_ForceIn, out force)){
                    door.ForceIn = float.Parse(force.RawValue);
                    Debug.Log("ForceIn "+force.RawValue);
                }

                if(properties.TryGetValue(Map.Property_ForceOut, out force)){
                    door.ForceOut = float.Parse(force.RawValue);
                    Debug.Log("ForceOut "+force.RawValue);
                }

                if(properties.TryGetValue(Map.Property_Goto, out force)){
                    door.GoTo = force.RawValue;
                    Debug.Log("Goto "+force.RawValue);
                }

                if(properties.TryGetValue(Map.Property_In, out force)){
                    door.In = (Direction) System.Enum.Parse(typeof(Direction), force.RawValue, true);
                    Debug.Log("In "+force.RawValue);
                }

                if(properties.TryGetValue(Map.Property_Out, out force)){
                    door.Out = (Direction) System.Enum.Parse(typeof(Direction), force.RawValue, true);
                    Debug.Log("Out "+force.RawValue);
                }
//.........这里部分代码省略.........
开发者ID:teamzeroth,项目名称:retroboy,代码行数:101,代码来源:MapExtensions.cs


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