Exemplo n.º 1
0
        protected override void OnPreviewSettingGUI()
        {
            GUILayout.Label("Object", EditorStyles.boldLabel);

            GameObject prefab = EditorGUILayout.ObjectField(new GUIContent("Prefab", "The prefab to be instantiate."), _tit.prefab, typeof(GameObject), false) as GameObject;

            if (prefab != _tit.prefab)
            {
                EditorUtility.SetDirty(_tit);
                Undo.RegisterCompleteObjectUndo(_tit, "Reassign Prefab");
                _tit.prefab = prefab;
            }

            if (_tit.prefab != null)
            {
                Transform parentTF   = TransformUtils.GetTransformByPath(_tit.parentPath);
                string    parentPath = (EditorGUILayout.ObjectField(new GUIContent("Parent in Scene", "The parent transform in current scene, this will be converted and saved as path string."), parentTF, typeof(Transform), true) as Transform).ToPath();
                if (parentTF == null && !string.IsNullOrEmpty(_tit.parentPath))
                {
                    GUI.contentColor = Color.red;
                }
                string customTargetPath = EditorGUILayout.TextField(new GUIContent(string.IsNullOrEmpty(_tit.parentPath) ? "Enter Manually" : (parentTF == null ? "Not Found" : " "), "Manually set the target path, use this for dynamically-loaded prefab."), _tit.parentPath);
                if (customTargetPath != _tit.parentPath)
                {
                    EditorUtility.SetDirty(_tit);
                    Undo.RegisterCompleteObjectUndo(_tit, "Reassign Custom Parent Path");
                    _tit.parentPath = customTargetPath;
                    parentPath      = customTargetPath;
                }
                if (parentTF == null && !string.IsNullOrEmpty(_tit.parentPath))
                {
                    GUI.contentColor = Color.white;
                }
                if ((string.IsNullOrEmpty(_tit.parentPath) || parentTF != null) && parentPath != _tit.parentPath)
                {
                    EditorUtility.SetDirty(_tit);
                    Undo.RegisterCompleteObjectUndo(_tit, "Reassign Parent Path");
                    _tit.parentPath = parentPath;
                }

                Vector3 localPosition = EditorGUILayout.Vector3Field(new GUIContent("Local Position", "Local position of the instantiated prefab."), _tit.localPosition);
                if (localPosition != _tit.localPosition)
                {
                    EditorUtility.SetDirty(_tit);
                    Undo.RegisterCompleteObjectUndo(_tit, "Reassign Local Position");
                    _tit.localPosition = localPosition;
                    UpdatePreview();
                }

                Vector3 localRotation = EditorGUILayout.Vector3Field(new GUIContent("Local Rotation", "Local rotation of the instantiated prefab."), _tit.localRotation);

                if (localRotation != _tit.localRotation)
                {
                    EditorUtility.SetDirty(_tit);
                    Undo.RegisterCompleteObjectUndo(_tit, "Reassign Local Rotation");
                    _tit.localRotation = localRotation;
                    UpdatePreview();
                }
            }
        }
 public override bool IsValidate()
 {
     if (!string.IsNullOrEmpty(targetPath) && TransformUtils.GetTransformByPath(targetPath) == null)
     {
         return(false);
     }
     return(true);
 }
        protected override void OnOtherSettingGUI()
        {
            AnimationClip addAnimationClip = EditorGUILayout.ObjectField("Add Animation Clip", _tat.animationClip, typeof(AnimationClip), false) as AnimationClip;

            if (addAnimationClip != _tat.animationClip)
            {
                EditorUtility.SetDirty(_tat);
                Undo.RegisterCompleteObjectUndo(_tat, "Reassign Add Animation Clip");
                _tat.animationClip = addAnimationClip;
            }

            if (addAnimationClip != null)
            {
                Transform animationTF   = TransformUtils.GetTransformByPath(_tat.animationPath);
                string    animationPath = TransformUtils.ToPath(EditorGUILayout.ObjectField("Animation Transform in Scene", animationTF, typeof(Transform), true) as Transform);
                if (!string.IsNullOrEmpty(_tat.animationPath) && animationTF == null)                   // Set but targetTF not found, this may be because in wrong scene
                {
                    GUI.contentColor = Color.red;
                    string customAnimationPath = EditorGUILayout.TextField("Not Found!", _tat.animationPath);
                    if (customAnimationPath != _tat.animationPath)
                    {
                        EditorUtility.SetDirty(_tat);
                        Undo.RegisterCompleteObjectUndo(_tat, "Reassign Custom Animation Path");
                        _tat.animationPath = customAnimationPath;
                    }
                    GUI.contentColor = Color.white;
                }
                if (animationTF != null)
                {
                    GUI.contentColor = Color.green;
                    if (animationTF.GetComponent <Animation>() == null)
                    {
                        GUILayout.Label("An Animation component will be added in runtime");
                    }
                    else
                    {
                        GUILayout.Label("The animation clip will be added to Animation in runtime");
                    }
                    GUI.contentColor = Color.white;
                }
                if (!string.IsNullOrEmpty(animationPath) && animationPath != _tat.animationPath)
                {
                    EditorUtility.SetDirty(_tat);
                    Undo.RegisterCompleteObjectUndo(_tat, "Reassign Animation Path");
                    _tat.animationPath = animationPath;
                }
            }

            OnDisableButtonsSettingGUI();
            OnDoNotResetOnCompleteSettingGUI();
        }
Exemplo n.º 4
0
        public override bool Init()
        {
            if (prefab == null)
            {
                Debug.LogErrorFormat("{0}:{1}:Init - Prefab not set", name, GetType());
                return(false);
            }

            if (!string.IsNullOrEmpty(parentPath) && TransformUtils.GetTransformByPath(parentPath) == null)
            {
                Debug.LogErrorFormat("{0}:{1}:Init - Parent not found, parentPath={2}", name, GetType(), parentPath);
                return(false);
            }

            return(true);
        }
Exemplo n.º 5
0
        protected override void OnPreviewSettingGUI()
        {
            Transform targetTF   = TransformUtils.GetTransformByPath(_tat.targetPath);
            string    targetPath = (EditorGUILayout.ObjectField(new GUIContent("Target in Scene", "The target transform in current scene, this will be converted and saved as path string."), targetTF, typeof(Transform), true) as Transform).ToPath();

            if (targetTF == null && !string.IsNullOrEmpty(_tat.targetPath))
            {
                GUI.contentColor = Color.red;
            }
            string customTargetPath = EditorGUILayout.TextField(new GUIContent(string.IsNullOrEmpty(_tat.targetPath) ? "Enter Manually" : (targetTF == null ? "Not Found" : " "), "Manually set the target path, use this for dynamically-loaded prefab."), _tat.targetPath);

            if (customTargetPath != _tat.targetPath)
            {
                EditorUtility.SetDirty(_tat);
                Undo.RegisterCompleteObjectUndo(_tat, "Reassign Custom Target Path");
                _tat.targetPath = customTargetPath;
                targetPath      = customTargetPath;
            }
            if (targetTF == null && !string.IsNullOrEmpty(_tat.targetPath))
            {
                GUI.contentColor = Color.white;
            }
            if ((string.IsNullOrEmpty(_tat.targetPath) || targetTF != null) && targetPath != _tat.targetPath)
            {
                EditorUtility.SetDirty(_tat);
                Undo.RegisterCompleteObjectUndo(_tat, "Reassign Target Path");
                _tat.targetPath = targetPath;
            }

            bool isActivate = EditorGUILayout.Toggle(new GUIContent("Is Activate", "Set the target GameObject to be active or not."), _tat.isActivate);

            if (isActivate != _tat.isActivate)
            {
                EditorUtility.SetDirty(_tat);
                Undo.RegisterCompleteObjectUndo(_tat, "Reassign Is Activate");
                _tat.isActivate = isActivate;
            }

            bool checkOnUpdate = EditorGUILayout.Toggle(new GUIContent("Check On Update", "Set the active status in Update, set this for if target GameObject's active status also controlled by another script."), _tat.checkOnUpdate);

            if (checkOnUpdate != _tat.checkOnUpdate)
            {
                EditorUtility.SetDirty(_tat);
                Undo.RegisterCompleteObjectUndo(_tat, "Reassign Check On Update");
                _tat.checkOnUpdate = checkOnUpdate;
            }
        }
        public override bool Init()
        {
            if (checkTarget)
            {
                if (string.IsNullOrEmpty(targetPath))
                {
                    Debug.LogErrorFormat("{0}:{1}:Init - Target object not set, targetPath={2}", name, GetType(), targetPath);
                    return(false);
                }

                targetTF = TransformUtils.GetTransformByPath(targetPath);
                if (targetTF == null)
                {
                    Debug.LogErrorFormat("{0}:{1}:Init - Target transform not found, targetPath={2}", name, GetType(), targetPath);
                    return(false);
                }

                if (skipIfTargetInactive && !targetTF.gameObject.activeInHierarchy)
                {
                    Debug.LogErrorFormat("{0}:{1}:Init - Target object not active", name, GetType());
                    return(false);
                }
            }

            _disableButtons = new Button[disableButtonPaths.Length];
            for (int i = 0, imax = disableButtonPaths.Length; i < imax; i++)
            {
                Button b = TransformUtils.GetComponentByPath <Button>(disableButtonPaths[i]);
                if (b == null)
                {
                    Debug.LogErrorFormat("{0}:{1}:Init - Disable collider not found, disableButtonPaths={2}", name, GetType(), disableButtonPaths[i]);
                }
                _disableButtons[i] = b;
            }

            tutorialPanel = TutorialPanel.current;
            if (tutorialPanel == null)
            {
                Debug.LogErrorFormat("{0}:{1}:Init - TutorialPanel instance not found, targetPath={2}", name, GetType(), targetPath);
                return(false);
            }

            tutorialPanel.Reset(!showBackgroundMask);

            return(true);
        }
        private void PlayAnimation()
        {
            if (animationClip == null)
            {
                return;
            }

            Transform animationTF = targetTF;

            if (!string.IsNullOrEmpty(animationPath))
            {
                animationTF = TransformUtils.GetTransformByPath(animationPath);
            }

            if (animationTF == null)
            {
                return;
            }

            Animation animation = animationTF.GetComponent <Animation>();

            if (animation != null)               // There's already animation component attached

            {
                bool containClip = false;
                animation.clip = animationClip;
                animation.Play();
            }
            else
            {
                if (_addedAnimation != null)
                {
                    Destroy(_addedAnimation);
                }

                _addedAnimation      = animationTF.gameObject.AddComponent <Animation>();
                _addedAnimation.clip = animationClip;
                _addedAnimation.playAutomatically = true;

                // Re-active the animation
                animationTF.gameObject.SetActive(false);
                animationTF.gameObject.SetActive(true);
            }
        }
Exemplo n.º 8
0
        public override bool Init()
        {
            if (!string.IsNullOrEmpty(targetPath))
            {
                Transform targetTF = TransformUtils.GetTransformByPath(targetPath);
                if (targetTF == null)
                {
                    Debug.LogError(string.Format("{0}:{1}:Init - Can't find target Panel with targetPath={2}", name, GetType(), targetPath));
                    return(false);
                }
                targetPanel = targetTF.GetComponent <Panel>();
                if (targetPanel == null)
                {
                    Debug.LogError(string.Format("{0}:{1}:Init - Target doesn't contain an Panel component, targetPath={2}", name, GetType(), targetPath));
                    return(false);
                }
            }

            return(base.Init());
        }
        public override bool Init()
        {
            if (string.IsNullOrEmpty(targetPath))
            {
                Debug.LogErrorFormat("{0}:{1}:Init - Target object not set, targetPath={2}", name, GetType(), targetPath);
                return(false);
            }

            Transform targetTF = TransformUtils.GetTransformByPath(targetPath);

            if (targetTF == null)
            {
                Debug.LogErrorFormat("{0}:{1}:Init - Target transform not found, targetPath={2}", name, GetType(), targetPath);
                return(false);
            }

            targetGO = targetTF.gameObject;

            return(true);
        }
        protected override void OnOtherSettingGUI()
        {
            Transform targetTF   = TransformUtils.GetTransformByPath(_tect.targetPath);
            string    targetPath = (EditorGUILayout.ObjectField(new GUIContent("Target in Scene", "The target transform in current scene, this will be converted and saved as path string."), targetTF, typeof(Transform), true) as Transform).ToPath();

            if (targetTF == null && !string.IsNullOrEmpty(_tect.targetPath))
            {
                GUI.contentColor = Color.red;
            }
            string customTargetPath = EditorGUILayout.TextField(string.IsNullOrEmpty(_tect.targetPath) ? "Enter Manually" : (targetTF == null ? "Not Found" : " "), _tect.targetPath);

            if (customTargetPath != _tect.targetPath)
            {
                EditorUtility.SetDirty(_tect);
                Undo.RegisterCompleteObjectUndo(_tect, "Reassign Custom Target Path");
                _tect.targetPath = customTargetPath;
                targetPath       = customTargetPath;
            }
            if (targetTF == null && !string.IsNullOrEmpty(_tect.targetPath))
            {
                GUI.contentColor = Color.white;
            }
            if ((string.IsNullOrEmpty(_tect.targetPath) || targetTF != null) && targetPath != _tect.targetPath)
            {
                EditorUtility.SetDirty(_tect);
                Undo.RegisterCompleteObjectUndo(_tect, "Reassign Target Path");
                _tect.targetPath = targetPath;
            }

            if (targetTF != null)
            {
                Component[]  components          = targetTF.GetComponents <Component>();
                int          savedComponentIndex = -1;
                GUIContent[] componentContents   = new GUIContent[components.Length];
                for (int i = 0, imax = components.Length; i < imax; i++)
                {
                    componentContents[i] = new GUIContent(components[i].GetType().ToString(), "");
                    if (components[i].GetType().ToString() == _tect.targetComponentName)
                    {
                        savedComponentIndex = i;
                    }
                }

                int selectedComponentIndex = EditorGUILayout.Popup(new GUIContent("Component", "The script that contain the variable."), savedComponentIndex, componentContents);
                if (selectedComponentIndex != savedComponentIndex)
                {
                    EditorUtility.SetDirty(_tect);
                    Undo.RegisterCompleteObjectUndo(_tect, "Reassign Component");
                    _tect.targetComponentName = components[selectedComponentIndex].GetType().ToString();
                }

                if (!string.IsNullOrEmpty(_tect.targetComponentName))
                {
                    if (selectedComponentIndex >= components.Length)
                    {
                        selectedComponentIndex = components.Length - 1;
                    }
                    Component   c          = components.Length > 0 ? components[selectedComponentIndex] : null;
                    FieldInfo[] fieldInfos = components[selectedComponentIndex].GetType().GetFields(BindingFlags.Public | BindingFlags.Instance);

                    int          savedFieldIndex = 0;
                    GUIContent[] fieldContents   = new GUIContent[fieldInfos.Length + 1];                   // First null
                    fieldContents[0] = new GUIContent("<null>", "");
                    for (int i = 0, imax = fieldInfos.Length; i < imax; i++)
                    {
                        fieldContents[i + 1] = new GUIContent(fieldInfos[i].Name, "");
                        if (fieldInfos[i].Name == _tect.fieldName)
                        {
                            savedFieldIndex = i + 1;
                        }
                    }

                    int selectedObjectIndex = EditorGUILayout.Popup(new GUIContent("Field Object", "The variable field name."), savedFieldIndex, fieldContents);
                    if (selectedObjectIndex != savedFieldIndex)
                    {
                        EditorUtility.SetDirty(_tect);
                        Undo.RegisterCompleteObjectUndo(_tect, "Reassign Field Object");
                        _tect.fieldName = fieldInfos[selectedObjectIndex].Name;
                    }

                    EventInfo[] eventInfos;
                    if (string.IsNullOrEmpty(_tect.fieldName) || c == null)
                    {
                        eventInfos = c.GetType().GetEvents(BindingFlags.Public | BindingFlags.Instance);
                    }
                    else
                    {
                        object obj = (object)c.GetType().GetField(_tect.fieldName, BindingFlags.Public | BindingFlags.Instance).GetValue(c);
                        eventInfos = obj.GetType().GetEvents(BindingFlags.Public | BindingFlags.Instance);
                    }

                    if (eventInfos.Length == 0)
                    {
                        GUI.contentColor = Color.red;
                        EditorGUILayout.LabelField("Event", "Not Found");
                        GUI.contentColor = Color.white;
                    }
                    else
                    {
                        int          savedEventIndex = -1;
                        GUIContent[] actionsContents = new GUIContent[eventInfos.Length];
                        for (int i = 0, imax = eventInfos.Length; i < imax; i++)
                        {
                            actionsContents[i] = new GUIContent(eventInfos[i].Name, "");
                            if (eventInfos[i].Name == _tect.eventName)
                            {
                                savedEventIndex = i;
                            }
                        }

                        int selectedActionIndex = EditorGUILayout.Popup(new GUIContent("Event", "The event field name."), savedEventIndex, actionsContents);
                        if (selectedActionIndex != savedEventIndex)
                        {
                            EditorUtility.SetDirty(_tect);
                            Undo.RegisterCompleteObjectUndo(_tect, "Reassign Event");
                            _tect.eventName = eventInfos[selectedActionIndex].Name;
                        }
                    }
                }
            }
        }
        public override bool Init()
        {
            if (string.IsNullOrEmpty(targetPath))
            {
                Debug.LogErrorFormat("{0}:{1}:Init - Target path not set", name, GetType());
                return(false);
            }

            Transform targetTF = TransformUtils.GetTransformByPath(targetPath);

            if (targetTF == null)
            {
                Debug.LogErrorFormat("{0}:{1}:Init - Target transform not found, targetPath={2}", name, GetType(), targetPath);
                return(false);
            }

            if (string.IsNullOrEmpty(targetComponentName))
            {
                Debug.LogErrorFormat("{0}:{1}:Init - Target component not set", name, GetType());
                return(false);
            }

            System.Type targetComponentType = System.Type.GetType(targetComponentName);

            if (targetComponentType == null)
            {
                Debug.LogErrorFormat("{0}:{1}:Init - Target component type not found, targetComponentName={2}", name, GetType(), targetComponentName);
                return(false);
            }

            Component targetC = targetTF.GetComponent(targetComponentName) as Component;

            if (targetC == null)
            {
                Debug.LogErrorFormat("{0}:{1}:Init - Target component not found, targetComponentType={2}", name, GetType(), targetComponentType);
                return(false);
            }

            UnityAction handler = DoComplete;

            if (string.IsNullOrEmpty(fieldName))
            {
                try {
                    EventInfo ei = targetComponentType.GetEvent(eventName, BindingFlags.Public | BindingFlags.Instance);
                    ei.AddEventHandler(targetC, handler);
                } catch {
                    Debug.LogWarningFormat("{0}:{1}:Init - Action not found, targetC={2}, actionName={3}", name, GetType(), targetC, eventName);
                    return(false);
                }
            }
            else
            {
                object obj;

                try {
                    obj = (object)targetComponentType.GetField(fieldName, BindingFlags.Public | BindingFlags.Instance).GetValue(targetC);
                } catch {
                    Debug.LogWarningFormat("{0}:{1}:Init - Target field not found, targetC={2}, fieldName={3}", name, GetType(), targetC, fieldName);
                    return(false);
                }

                try {
                    EventInfo ei = obj.GetType().GetEvent(eventName, BindingFlags.Public | BindingFlags.Instance);
                    ei.AddEventHandler(obj, handler);
                } catch {
                    Debug.LogWarningFormat("{0}:{1}:Init - Event not found, targetC={2}, obj={3}, eventName={4}", name, GetType(), targetC, obj, eventName);
                    return(false);
                }
            }

            return(true);
        }
        protected override void OnPreviewSettingGUI()
        {
            _showTargetSetting = EditorGUILayout.Foldout(_showTargetSetting, "Target");

            if (_showTargetSetting)
            {
                EditorGUI.indentLevel++;

                Transform targetTF    = TransformUtils.GetTransformByPath(_tht.targetPath);
                Transform newTargetTF = EditorGUILayout.ObjectField(new GUIContent("Target in Scene", "The target transform in current scene, this will be converted and saved as path string."), targetTF, typeof(Transform), true) as Transform;
                string    targetPath  = newTargetTF.ToPath();
                if (targetTF == null && !string.IsNullOrEmpty(_tht.targetPath))
                {
                    GUI.contentColor = Color.red;
                }
                string customTargetPath = EditorGUILayout.TextField(new GUIContent(string.IsNullOrEmpty(_tht.targetPath) ? "Enter Manually" : (targetTF == null ? "Not Found" : " "), "Manually set the target path, use this for dynamically-loaded prefab."), _tht.targetPath);
                if (customTargetPath != _tht.targetPath)
                {
                    EditorUtility.SetDirty(_tht);
                    Undo.RegisterCompleteObjectUndo(_tht, "Reassign Custom Target Path");
                    _tht.targetPath = customTargetPath;
                    targetPath      = customTargetPath;
                }
                if (targetTF == null && !string.IsNullOrEmpty(_tht.targetPath))
                {
                    GUI.contentColor = Color.white;
                }
                if ((string.IsNullOrEmpty(_tht.targetPath) || newTargetTF != null) && targetPath != _tht.targetPath)
                {
                    EditorUtility.SetDirty(_tht);
                    Undo.RegisterCompleteObjectUndo(_tht, "Reassign Target Path");
                    _tht.targetPath = targetPath;
                }

                if (!string.IsNullOrEmpty(_tht.targetPath))
                {
                    bool skipIfTargetInactive = EditorGUILayout.Toggle(new GUIContent("Skip If Target Inactive", "Mark this task complete if finding the target inactive."), _tht.skipIfTargetInactive);
                    if (skipIfTargetInactive != _tht.skipIfTargetInactive)
                    {
                        EditorUtility.SetDirty(_tht);
                        Undo.RegisterCompleteObjectUndo(_tht, "Reassign Skip If Target Inactive");
                        _tht.skipIfTargetInactive = skipIfTargetInactive;
                    }
                    bool cloneTarget = EditorGUILayout.Toggle(new GUIContent("Clone Target", "Clone a target and keep it in original place, use this on scroll slot etc."), _tht.cloneTarget);
                    if (cloneTarget != _tht.cloneTarget)
                    {
                        EditorUtility.SetDirty(_tht);
                        Undo.RegisterCompleteObjectUndo(_tht, "Reassign Clone Target");
                        _tht.cloneTarget = cloneTarget;
                    }

                    if (cloneTarget)
                    {
                        bool targetFollowCloneOnUpdate = EditorGUILayout.Toggle(new GUIContent("Target Follow Clone On Update", "Target follows the clone in update, use this on scroll slot etc."), _tht.targetFollowCloneOnUpdate);
                        if (targetFollowCloneOnUpdate != _tht.targetFollowCloneOnUpdate)
                        {
                            EditorUtility.SetDirty(_tht);
                            Undo.RegisterCompleteObjectUndo(_tht, "Reassign Target Follow Clone On Update");
                            _tht.targetFollowCloneOnUpdate = targetFollowCloneOnUpdate;
                        }
                        bool targetCanCatchRaycast = EditorGUILayout.Toggle(new GUIContent("Target Catch Raycast", "Toggle the target raycast, use this if you want tto turn on/off the target's interaction."), _tht.targetCanCatchRaycast);
                        if (targetCanCatchRaycast != _tht.targetCanCatchRaycast)
                        {
                            EditorUtility.SetDirty(_tht);
                            Undo.RegisterCompleteObjectUndo(_tht, "Reassign Target Can Catch Raycast");
                            _tht.targetCanCatchRaycast = targetCanCatchRaycast;
                        }
                        bool putCloneToTutorialPanelInstead = EditorGUILayout.Toggle(new GUIContent("Put Clone To Tutorial Panel Instead", "By default, put original target to tutorial panel, turn this on if you want the opposite."), _tht.putCloneToTutorialPanelInstead);
                        if (putCloneToTutorialPanelInstead != _tht.putCloneToTutorialPanelInstead)
                        {
                            EditorUtility.SetDirty(_tht);
                            Undo.RegisterCompleteObjectUndo(_tht, "Reassign Put Clone To Tutorial Panel Instead");
                            _tht.putCloneToTutorialPanelInstead = putCloneToTutorialPanelInstead;
                        }
                    }
                }

                EditorGUI.indentLevel--;
            }

            base.OnPreviewSettingGUI();
        }