當前位置: 首頁>>代碼示例>>C#>>正文


C# MapObject.GetPropertyAsInt方法代碼示例

本文整理匯總了C#中X_UniTMX.MapObject.GetPropertyAsInt方法的典型用法代碼示例。如果您正苦於以下問題:C# MapObject.GetPropertyAsInt方法的具體用法?C# MapObject.GetPropertyAsInt怎麽用?C# MapObject.GetPropertyAsInt使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在X_UniTMX.MapObject的用法示例。


在下文中一共展示了MapObject.GetPropertyAsInt方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: ApplyCustomProperties

        /// <summary>
        /// Applies to gameObject any custom X-UniTMX properties present on obj
        /// </summary>
        /// <param name="gameObject">GameObject to apply custom properties to</param>
        /// <param name="obj">MapObject to read custom properties from</param>
        public void ApplyCustomProperties(GameObject gameObject, MapObject obj)
        {
            // nothing to do here...
            if (gameObject == null || obj == null)
                return;

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

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

            // Add a tag for gameObject
            if (obj.HasProperty(Property_Tag))
                gameObject.tag = obj.GetPropertyAsString(Property_Tag);
            // Add Components for this gameObject
            int c = 1;
            while (obj.HasProperty(Property_AddComponent + c))
            {
                UnityEngineInternal.APIUpdaterRuntimeServices.AddComponent(gameObject, "Assets/X-UniTMX/Code/Map.cs (2684,5)", obj.GetPropertyAsString(Property_AddComponent + c));
                c++;
            }
            c = 1;
            while (obj.HasProperty(Property_SendMessage + c))
            {
                string messageToSend = obj.GetPropertyAsString(Property_SendMessage + c);
                string[] menssage = messageToSend.Split('|');
                if (menssage.Length == 2)
                {
                    gameObject.BroadcastMessage(menssage[0], menssage[1]);
                }
                if (menssage.Length == 1)
                {
                    gameObject.BroadcastMessage(menssage[0]);
                }
                c++;
            }

            if (gameObject.GetComponent<Renderer>() != null)
            {
                if (obj.HasProperty(Property_SortingLayerName))
                    gameObject.GetComponent<Renderer>().sortingLayerName = obj.GetPropertyAsString(Property_SortingLayerName);

                if (obj.HasProperty(Property_SortingOrder))
                    gameObject.GetComponent<Renderer>().sortingOrder = obj.GetPropertyAsInt(Property_SortingOrder);

                if (obj.HasProperty(Property_SetMaterialColor))
                {
                    string[] splitColor = obj.GetPropertyAsString(Property_SetMaterialColor).Split(',');
                    if (splitColor.Length >= 1)
                    {
                        gameObject.GetComponent<Renderer>().material = new Material(BaseTileMaterial);
                        gameObject.GetComponent<Renderer>().material.color = new Color32(
                            ((byte)(int.Parse(string.IsNullOrEmpty(splitColor[0]) ? "255" : splitColor[0]))),
                            splitColor.Length >= 2 ? ((byte)(int.Parse(splitColor[1]))) : (byte)255,
                            splitColor.Length >= 3 ? ((byte)(int.Parse(splitColor[2]))) : (byte)255,
                            splitColor.Length >= 4 ? ((byte)(int.Parse(splitColor[3]))) : (byte)255);
                    }
                }
            }
        }
開發者ID:BoldBigflank,項目名稱:rodball,代碼行數:67,代碼來源:Map.cs


注:本文中的X_UniTMX.MapObject.GetPropertyAsInt方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。