예제 #1
0
    private void Awake()
    {
#if !UNITY_EDITOR
        try
        {
#endif


#if !UNITY_EDITOR
        StartCoroutine(DelayShowScreen());
        PlatformHelper.PlayLogoMovie();
#endif
        TargetBindingProperty.Register();

        // var channel = PlatformHelper.GetChannelString();
        // Logger.Debug("PlatformHelper.GetChannelString = " + channel);
        GameSetting.Channel = GameUtils.GetChannelString();

        PlatformHelper.Initialize();
        if (null != Instance)
        {
            Logger.Fatal("ERROR!!!!!!!!!!!!!!!!!!! Game has been created");
            return;
        }
        Instance = this;

        var Fps = PlayerPrefs.GetInt(GameSetting.LowFpsKey, 30);
        Application.targetFrameRate = Fps;
#if UNITY_EDITOR
        Application.targetFrameRate = 80;
#endif
        //注册所有解析表中表达式中的函数
        ExpressionHelper.RegisterAllFunction();
        PlayCG.Instance.Init();

        mMgrList = new List <IManager>
        {
            ObjManager.Instance,
            SceneManager.Instance,
            PlayerDataManager.Instance,
            ResourceManager.Instance,
            EffectManager.Instance,
            UIManager.Instance,
            SoundManager.Instance
        };

        DontDestroyOnLoad(gameObject);


#if !UNITY_EDITOR
    }

    catch (Exception ex)
    {
        Logger.Error(ex.ToString());
    }
#endif
    }
    /// <summary>
    /// Draw the actual property.
    /// </summary>


    public override void OnGUI(Rect rect, SerializedProperty prop, GUIContent label)
    {
        SerializedProperty target = prop.FindPropertyRelative("mTarget");
        SerializedProperty field  = prop.FindPropertyRelative("mName");

        rect.height = 16f;
        EditorGUI.PropertyField(rect, target, label);

        if (target.objectReferenceValue != null &&
            target.serializedObject.targetObject != null)
        {
            Component comp1 = target.objectReferenceValue as Component;
            Component comp2 = target.serializedObject.targetObject as Component;

            if (comp1.gameObject != comp2.gameObject)
            {
                GameObject o = comp2.gameObject;

                if (comp2.gameObject.GetComponent(comp1.GetType()))
                {
                    Component l = o.GetComponent(comp1.GetType());
                    target.objectReferenceValue = l;
                }
                else
                {
                    Debug.LogError(string.Format("Can not paste different type to this game object. {0} to {1}", comp1.GetType(), comp2.GetType()));
                }
            }
        }

        Component comp = target.objectReferenceValue as Component;

        if (comp == null)
        {
            target.objectReferenceValue = target.serializedObject.targetObject;

            comp = target.objectReferenceValue as Component;
            GameObject obj = comp.gameObject;
            if (obj)
            {
                UILabel l = obj.GetComponent <UILabel>();
                if (l != null)
                {
                    target.objectReferenceValue = l as Component;
                    field.stringValue           = "text";
                }
            }
        }

        if (comp != null)
        {
            rect.y     += 18f;
            GUI.changed = false;
            EditorGUI.BeginDisabledGroup(target.hasMultipleDifferentValues);
            int index = 0;

            // Get all the properties on the target game object
            List <Entry> list = GetProperties(comp.gameObject, mustRead, mustWrite);

            // We want the field to look like "Component.property" rather than just "property"
            string current = TargetBindingProperty.ToString(target.objectReferenceValue as Component, field.stringValue);

            // Convert all the properties to names
            string[] names = TargetBindingPropertyDrawer.GetNames(list, current, out index);

            // Draw a selection list
            GUI.changed = false;
            rect.xMin  += EditorGUIUtility.labelWidth;
            rect.width -= 18f;
            int choice = EditorGUI.Popup(rect, "", index, names);

            // Update the target object and property name
            if (GUI.changed && choice > 0)
            {
                Entry ent = list[choice - 1];
                target.objectReferenceValue = ent.target;
                field.stringValue           = ent.name;
            }
            EditorGUI.EndDisabledGroup();
        }
    }
    /// <summary>
    /// Collect a list of usable properties and fields.
    /// </summary>

    static public List <Entry> GetProperties(GameObject target, bool read, bool write)
    {
        Component[] comps = target.GetComponents <Component>();

        List <Entry> list = new List <Entry>();

        for (int i = 0, imax = comps.Length; i < imax; ++i)
        {
            Component comp = comps[i];
            if (comp == null)
            {
                continue;
            }

            Type           type   = comp.GetType();
            BindingFlags   flags  = BindingFlags.Instance | BindingFlags.Public;
            FieldInfo[]    fields = type.GetFields(flags);
            PropertyInfo[] props  = type.GetProperties(flags);

            // The component itself without any method
            if (TargetBindingProperty.Convert(comp, filter))
            {
                Entry ent = new Entry();
                ent.target = comp;
                list.Add(ent);
            }

            for (int b = 0; b < fields.Length; ++b)
            {
                FieldInfo field = fields[b];

                if (filter != typeof(void))
                {
                    if (canConvert)
                    {
                        if (!TargetBindingProperty.Convert(field.FieldType, filter))
                        {
                            continue;
                        }
                    }
                    else if (!filter.IsAssignableFrom(field.FieldType))
                    {
                        continue;
                    }
                }

                Entry ent = new Entry();
                ent.target = comp;
                ent.name   = field.Name;
                list.Add(ent);
            }

            for (int b = 0; b < props.Length; ++b)
            {
                PropertyInfo prop = props[b];
                if (read && !prop.CanRead)
                {
                    continue;
                }
                if (write && !prop.CanWrite)
                {
                    continue;
                }

                if (filter != typeof(void))
                {
                    if (canConvert)
                    {
                        if (!TargetBindingProperty.Convert(prop.PropertyType, filter))
                        {
                            continue;
                        }
                    }
                    else if (!filter.IsAssignableFrom(prop.PropertyType))
                    {
                        continue;
                    }
                }

                Entry ent = new Entry();
                ent.target = comp;
                ent.name   = prop.Name;
                list.Add(ent);
            }
        }
        list.Add(new Entry()
        {
            name   = "Null",
            target = target.transform
        });
        return(list);
    }
예제 #4
0
        public bool TypeConvert(object o, TargetBindingProperty target)
        {
            if (string.IsNullOrEmpty(target.name))
            {
                return(false);
            }
            if (target.name == "atlas")
            {
                var sprite = target.target.GetComponent <UISprite>();
                if (sprite == null)
                {
                    return(true);
                }
                var currentValue = "";
                if (sprite.atlas != null)
                {
                    currentValue = sprite.atlas.name;
                    if (currentValue.Equals(o.ToString()))
                    {
                        return(true);
                    }
                }
                var targetValue = "";
                var value       = o.ToString();
                if (value == "Grey")
                {
//需要把原本的设为灰度
                    if (currentValue.Contains("Grey"))
                    {
                        return(true);
                    }
                    //原来不是灰度
                    targetValue = currentValue + "Grey";
                }
                else if (value == "NotGrey")
                {
//需要把原本的设为彩色
                    if (currentValue.Contains("Grey"))
                    {
                        targetValue = currentValue.Remove(currentValue.Length - 4, 4);
                    }
                    else
                    {
//原来不是灰度
                        return(true);
                    }
                }
                else
                {
                    targetValue = value;
                }

                if (currentValue.Equals(targetValue))
                {
                    return(true);
                }
                target.AtlasValue = targetValue;

                if (targetValue.Contains("Circle"))
                {
                    var i = 1;
                }
                ResourceManager.PrepareResource <GameObject>("UI/Atlas/" + target.AtlasValue + ".prefab",
                                                             res =>
                {
                    if (res == null)
                    {
                        return;
                    }
                    //异步加载找不到原控件
                    if (target.target == null)
                    {
                        return;
                    }
                    if (targetValue == target.AtlasValue)
                    {
                        target.Set(res.GetComponent <UIAtlas>());
                    }
                }, true, true, true, false, true);
                return(true);
            }
            if (target.name == "mainTexture")
            {
                target.AtlasValue = o.ToString();
                ResourceManager.PrepareResource <Texture>(o.ToString(), res =>
                {
                    if (o.ToString() == target.AtlasValue)
                    {
                        target.Set(res);
                    }
                }, true, true, false, false, true);
                return(true);
            }
            if (target.name == "color")
            {
                if (o is string)
                {
                    var c = GameUtils.StringToColor(o.ToString());
                    target.Set(c);
                    return(true);
                }
            }
            if (target.name == "gradientBottom")
            {
                if (o is string)
                {
                    var c = GameUtils.StringToColor(o.ToString());
                    target.Set(c);
                    return(true);
                }
            }
            return(false);
        }