Пример #1
0
    ///////////////////////////////////////////////////////////////////////////////
    // functions
    ///////////////////////////////////////////////////////////////////////////////

    // ------------------------------------------------------------------
    // Desc:
    // ------------------------------------------------------------------

    protected void OnEnable()
    {
        if (target != editPlane)
        {
            editPlane = target as exPlane;

            if (editPlane.renderer != null)
            {
                EditorUtility.SetSelectedWireframeHidden(editPlane.renderer, true);
                // EditorUtility.SetSelectedWireframeHidden(editPlane.renderer, false); // DEBUG
            }

            // get trans2d
            if (editPlane.GetComponent <exScreenPosition>() != null)
            {
                trans2d = Transform2D.Screen;
            }
            else if (editPlane.GetComponent <exViewportPosition>() != null)
            {
                trans2d = Transform2D.Viewport;
            }
            else
            {
                trans2d = Transform2D.None;
            }
        }
    }
Пример #2
0
    // ------------------------------------------------------------------
    // Desc:
    // ------------------------------------------------------------------

    public void UpdatePlane(exPlane _plane)
    {
        PlaneInfo planeInfo = null;

        for (int i = 0; i < planeInfoList.Count; ++i)
        {
            if (planeInfoList[i].plane == _plane)
            {
                planeInfo = planeInfoList[i];
                break;
            }
        }
        if (planeInfo == null)
        {
            Debug.LogWarning("Can't find plane info of " + _plane.name);
            return;
        }

        // update plane info material
        if (_plane.GetComponent <Renderer>() != null)
        {
            planeInfo.material = _plane.GetComponent <Renderer>().sharedMaterial;
        }

        // if we are in player or if we are running in editor
        if (Application.isPlaying)
        {
            exClipping clipPlane = _plane as exClipping;
            // if this is not a clip plane
            if (clipPlane == null)
            {
                ApplyClipMaterial(_plane);
            }
        }
    }
Пример #3
0
    // ------------------------------------------------------------------
    // Desc:
    // ------------------------------------------------------------------

    protected void InsertPlaneInfo(int _idx, exPlane _plane)
    {
        PlaneInfo planeInfo = new PlaneInfo();

        planeInfo.plane = _plane;
        if (_plane.GetComponent <Renderer>() != null)
        {
            planeInfo.material = _plane.GetComponent <Renderer>().sharedMaterial;
        }
        planeInfoList.Insert(_idx, planeInfo);
    }
Пример #4
0
    // ------------------------------------------------------------------
    // Desc:
    // ------------------------------------------------------------------

    protected void AddPlaneInfo(exPlane _plane)
    {
        PlaneInfo planeInfo = new PlaneInfo();

        planeInfo.plane = _plane;
        if (_plane.GetComponent <Renderer>() != null)
        {
            planeInfo.material = _plane.GetComponent <Renderer>().sharedMaterial;
        }
        planeInfoList.Add(planeInfo);
    }
Пример #5
0
    // ------------------------------------------------------------------
    // Desc:
    // ------------------------------------------------------------------

    protected bool RemovePlaneInfo(exPlane _plane)
    {
        for (int i = 0; i < planeInfoList.Count; ++i)
        {
            PlaneInfo pi = planeInfoList[i];
            if (_plane == pi.plane)
            {
                if (_plane.GetComponent <Renderer>() != null)
                {
                    _plane.GetComponent <Renderer>().sharedMaterial = pi.material;
                }
                planeInfoList.RemoveAt(i);
                return(true);
            }
        }
        return(false);
    }
Пример #6
0
    // ------------------------------------------------------------------
    /// OnEnable functoin inherit from exPlane.
    /// When enabled set to true, it will enable all the item in the planeInfoList
    // ------------------------------------------------------------------

    protected new void OnEnable()
    {
        base.OnEnable();
        Init();

        //
        for (int i = 0; i < planeInfoList.Count; ++i)
        {
            PlaneInfo pi    = planeInfoList[i];
            exPlane   plane = pi.plane;
            if (plane && plane.GetComponent <Renderer>() && plane.GetComponent <Renderer>().sharedMaterial)
            {
                Texture2D texture = plane.GetComponent <Renderer>().sharedMaterial.mainTexture as Texture2D;
                plane.GetComponent <Renderer>().material = textureToClipMaterialTable[texture];
            }
        }
    }
Пример #7
0
    // ------------------------------------------------------------------
    /// remove plane from clipping list
    // ------------------------------------------------------------------

    public bool RemovePlane(exPlane _plane)
    {
        bool result = RemovePlaneInfo(_plane);

        if (result)
        {
            _plane.clippingPlane = null;

            if (isDyanmic || (Application.isPlaying == false))
            {
                if (_plane.GetComponent <Renderer>() && _plane.GetComponent <Renderer>().sharedMaterial)
                {
                    CheckAndRemoveClipMaterial(_plane.GetComponent <Renderer>().sharedMaterial.mainTexture as Texture2D);
                }
            }
        }
        return(result);
    }
Пример #8
0
    // ------------------------------------------------------------------
    /// \param _plane the in plane
    /// \param _length the length of the collider
    /// sync the collider size
    // ------------------------------------------------------------------

    public static void UpdateColliderSize(this exPlane _plane, float _length)
    {
        Collider collider = _plane.GetComponent <Collider>();

        // update box collider
        if (collider is BoxCollider)
        {
            BoxCollider boxCollider  = collider as BoxCollider;
            Rect        boundingRect = _plane.boundingRect;
            float       center_x     = _plane.boundingRect.x + _plane.boundingRect.width * 0.5f;
            float       center_y     = _plane.boundingRect.y + _plane.boundingRect.height * 0.5f;

            boxCollider.center = new Vector3(center_x, center_y, boxCollider.center.z);
            boxCollider.size   = new Vector3(boundingRect.width, boundingRect.height, _length);

            // DELME {
            // switch ( _plane.plane ) {
            // case exSprite.Plane.XY:
            //     boxCollider.center = new Vector3 ( center_x, center_y, boxCollider.center.z );
            //     boxCollider.size = new Vector3( boundingRect.width, boundingRect.height, _length );
            //     break;

            // case exSprite.Plane.XZ:
            //     boxCollider.center = new Vector3 ( center_x, boxCollider.center.y, center_y );
            //     boxCollider.size = new Vector3( boundingRect.width, _length, boundingRect.height );
            //     break;

            // case exSprite.Plane.ZY:
            //     boxCollider.center = new Vector3 ( boxCollider.center.x, center_y, center_x );
            //     boxCollider.size = new Vector3( _length, boundingRect.height, boundingRect.width );
            //     break;
            // }
            // } DELME end

            return;
        }

        // update mesh collider
        if (collider is MeshCollider)
        {
            MeshFilter meshFilter = _plane.meshFilter;
            if (meshFilter)
            {
                Mesh         mesh         = meshFilter.sharedMesh;
                MeshCollider meshCollider = collider as MeshCollider;
                // NOTE: only in this way, mesh collider changes
                meshCollider.sharedMesh = null;
                meshCollider.sharedMesh = mesh;
            }
            return;
        }
    }
Пример #9
0
    // ------------------------------------------------------------------
    // Desc:
    // ------------------------------------------------------------------

    public override void OnInspectorGUI()
    {
        serializedObject.Update();

        // NOTE DANGER: Unity didn't allow user change script in custom inspector {
        SerializedProperty scriptProp = serializedObject.FindProperty("m_Script");

        EditorGUILayout.PropertyField(scriptProp);
        // } DANGER end

        DoInspectorGUI();
        serializedObject.ApplyModifiedProperties();

        // if we have sprite
        exPlane targetPlane = target as exPlane;

        if (targetPlane.hasSprite)
        {
            exSpriteBase spriteBase = targetPlane.GetComponent <exSpriteBase>();
            // if ( targetPlane.width != spriteBase.width ) {
            //     targetPlane.width = spriteBase.width;
            //     EditorUtility.SetDirty(targetPlane);
            // }

            // if ( targetPlane.height != spriteBase.height ) {
            //     targetPlane.height = spriteBase.height;
            //     EditorUtility.SetDirty(targetPlane);
            // }

            if (targetPlane.anchor != spriteBase.anchor)
            {
                targetPlane.anchor = spriteBase.anchor;
                EditorUtility.SetDirty(targetPlane);
            }

            if (targetPlane.offset != spriteBase.offset)
            {
                targetPlane.offset = spriteBase.offset;
                EditorUtility.SetDirty(targetPlane);
            }
        }
    }
Пример #10
0
    // ------------------------------------------------------------------
    // Desc:
    // ------------------------------------------------------------------

    static void ApplyClipMaterialInEditor(this exClipping _clipping, exPlane _plane)
    {
        Renderer r = _plane.GetComponent <Renderer>();

        if (r != null && r.sharedMaterial != null)
        {
            Texture2D texture = r.sharedMaterial.mainTexture as Texture2D;
            if (_clipping.textureToClipMaterialTable.ContainsKey(texture) == false)
            {
                r.sharedMaterial = exEditorHelper.GetDefaultMaterial(texture,
                                                                     texture.name
                                                                     + "-clipping-" + Mathf.Abs(_clipping.GetInstanceID()),
                                                                     "ex2D/Alpha Blended (Clipping)");
                _clipping.AddClipMaterial(texture, r.sharedMaterial);
            }
            else
            {
                r.sharedMaterial = _clipping.textureToClipMaterialTable[texture];
            }
        }
    }
Пример #11
0
    // ------------------------------------------------------------------
    // Desc:
    // ------------------------------------------------------------------

    protected void ApplyClipMaterial(exPlane _plane)
    {
        Renderer r = _plane.GetComponent <Renderer>();

        if (r != null && r.sharedMaterial != null)
        {
            Texture2D texture = r.sharedMaterial.mainTexture as Texture2D;
            if (texture != null)
            {
                if (textureToClipMaterialTable.ContainsKey(texture) == false)
                {
                    r.material             = new Material(Shader.Find("ex2D/Alpha Blended (Clipping)"));
                    r.material.mainTexture = texture;
                    AddClipMaterial(texture, r.material);
                }
                else
                {
                    r.material = textureToClipMaterialTable[texture];
                }
            }
        }
    }
Пример #12
0
    // ------------------------------------------------------------------
    // Desc:
    // ------------------------------------------------------------------

    public override void OnInspectorGUI()
    {
        exSprite editSprite = target as exSprite;

        inAnimMode = AnimationUtility.InAnimationMode();

#if UNITY_3_4
        isPrefab = (EditorUtility.GetPrefabType(target) == PrefabType.Prefab);
#else
        isPrefab = (PrefabUtility.GetPrefabType(target) == PrefabType.Prefab);
#endif

        // TEMP: not sure this is good {
        Event e = Event.current;
        if (e.type == EventType.MouseDown && e.button == 0 && e.clickCount == 1)
        {
            if (isPrefab)
            {
                Undo.RegisterUndo(editPlane, "editPlane");
            }
            else
            {
                Undo.RegisterSceneUndo("ex2D.Scene");
            }
        }
        // } TEMP end

        EditorGUIUtility.LookLikeInspector();
        EditorGUILayout.Space();
        ++EditorGUI.indentLevel;

        if (isPrefab && editPlane.meshFilter && editPlane.meshFilter.sharedMesh)
        {
            editPlane.meshFilter.sharedMesh = null;
        }

        // TODO: I do not know how to do it. {
        // // ========================================================
        // // Script
        // // ========================================================

        // MonoScript script = (MonoScript)AssetDatabase.LoadAssetAtPath( AssetDatabase.GetAssetPath (target), typeof(MonoScript) );
        // script = (MonoScript)EditorGUILayout.ObjectField( "Script", script, typeof(MonoScript) );
        // } TODO end

        // ========================================================
        // trans2d
        // ========================================================

        GUI.enabled = !inAnimMode;
        EditorGUIUtility.LookLikeControls();
        Transform2D newTrans2D = (Transform2D)EditorGUILayout.EnumPopup("Transform 2D", trans2d, GUILayout.Width(200), GUILayout.ExpandWidth(false));
        EditorGUIUtility.LookLikeInspector();
        GUI.enabled = true;

        //
        if (newTrans2D != trans2d)
        {
            trans2d = newTrans2D;

            exScreenPosition screenPos = editPlane.GetComponent <exScreenPosition>();
            if (screenPos != null)
            {
                Object.DestroyImmediate(screenPos, true);
            }
            exViewportPosition vpPos = editPlane.GetComponent <exViewportPosition>();
            if (vpPos != null)
            {
                Object.DestroyImmediate(vpPos, true);
            }

            switch (trans2d)
            {
            case Transform2D.None:
                break;

            case Transform2D.Screen:
                editPlane.gameObject.AddComponent <exScreenPosition>();
                break;

            case Transform2D.Viewport:
                editPlane.gameObject.AddComponent <exViewportPosition>();
                break;
            }
        }

        // ========================================================
        // use animation helper
        // ========================================================

        GUILayout.BeginHorizontal();
        GUILayout.Space(15);
        GUI.enabled = !inAnimMode;
        exAnimationHelper compAnimHelper = editPlane.GetComponent <exAnimationHelper>();
        bool hasAnimHelper = compAnimHelper != null;
        bool useAnimHelper = GUILayout.Toggle(hasAnimHelper, "Use Animation Helper");
        if (useAnimHelper != hasAnimHelper)
        {
            if (useAnimHelper)
            {
                AddAnimationHelper();
            }
            else
            {
                Object.DestroyImmediate(compAnimHelper, true);
            }
            GUI.changed = true;
        }
        GUI.enabled = true;
        GUILayout.EndHorizontal();

        // ========================================================
        // camera type
        // ========================================================

        GUI.enabled = !inAnimMode;
        EditorGUIUtility.LookLikeControls();
        if (isPrefab)
        {
            GUILayout.BeginHorizontal();
            bool isPrefabCamera = false;
            if (editPlane.renderCameraForPrefab != null)
            {
#if UNITY_3_4
                isPrefabCamera = (EditorUtility.GetPrefabType(editPlane.renderCameraForPrefab) == PrefabType.Prefab);
#else
                isPrefabCamera = (PrefabUtility.GetPrefabType(editPlane.renderCameraForPrefab) == PrefabType.Prefab);
#endif
            }
            editPlane.renderCamera = (Camera)EditorGUILayout.ObjectField("Camera"
                                                                         , isPrefabCamera ? editPlane.renderCameraForPrefab : null
                                                                         , typeof(Camera)
                                                                         , false
                                                                         , GUILayout.Width(300));
            labelStyle.fontStyle        = FontStyle.Bold;
            labelStyle.normal.textColor = Color.yellow;
            GUILayout.Label("(Prefab Only)", labelStyle);
            GUILayout.EndHorizontal();
            GUILayout.Space(5);
        }
        else
        {
            editPlane.renderCamera = (Camera)EditorGUILayout.ObjectField("Camera"
                                                                         , editPlane.renderCamera
                                                                         , typeof(Camera)
                                                                         , true
                                                                         , GUILayout.Width(300));
        }
        EditorGUIUtility.LookLikeInspector();

        // ========================================================
        // anchor
        // ========================================================

        EditorGUILayout.LabelField("Anchor", "");
        GUILayout.BeginHorizontal();
        GUILayout.Space(30);
        editPlane.anchor
            = (exPlane.Anchor)GUILayout.SelectionGrid((int)editPlane.anchor,
                                                      anchorTexts,
                                                      3,
                                                      GUILayout.Width(80));
        GUILayout.EndHorizontal();

        // ========================================================
        // use texture offset
        // ========================================================

        if (editSprite != null)
        {
            GUILayout.BeginHorizontal();
            GUILayout.Space(30);
            editSprite.useTextureOffset = GUILayout.Toggle(editSprite.useTextureOffset, "Use Texture Offset");
            GUILayout.EndHorizontal();
        }
        GUI.enabled = true;

        // ========================================================
        // offset
        // ========================================================

        EditorGUIUtility.LookLikeControls();
        editPlane.offset = EditorGUILayout.Vector2Field("Offset", editPlane.offset);
        EditorGUIUtility.LookLikeInspector();

        // ========================================================
        // check dirty
        // ========================================================

        if (GUI.changed)
        {
            EditorUtility.SetDirty(editPlane);
        }
        --EditorGUI.indentLevel;
    }
Пример #13
0
    // ------------------------------------------------------------------
    // Desc:
    // ------------------------------------------------------------------

    protected override void DoInspectorGUI()
    {
        base.DoInspectorGUI();

        // if settingsStyles is null
        if (styles == null)
        {
            styles = new Styles();
        }

        //
        GUILayout.BeginHorizontal();
        GUILayout.FlexibleSpace();
        if (GUILayout.Button("Sync Size", GUILayout.Width(70), GUILayout.Height(20)))
        {
            exPlane targetPlane = target as exPlane;
            if (targetPlane.hasSprite)
            {
                exSpriteBase spriteBase = targetPlane.GetComponent <exSpriteBase>();
                if (targetPlane.width != spriteBase.width)
                {
                    targetPlane.width = spriteBase.width;
                    EditorUtility.SetDirty(targetPlane);
                }

                if (targetPlane.height != spriteBase.height)
                {
                    targetPlane.height = spriteBase.height;
                    EditorUtility.SetDirty(targetPlane);
                }

                if (targetPlane.anchor != spriteBase.anchor)
                {
                    targetPlane.anchor = spriteBase.anchor;
                    EditorUtility.SetDirty(targetPlane);
                }

                if (targetPlane.offset != spriteBase.offset)
                {
                    targetPlane.offset = spriteBase.offset;
                    EditorUtility.SetDirty(targetPlane);
                }
            }
        }
        GUILayout.EndHorizontal();

        //
        EditorGUILayout.Space();
        EditorGUILayout.PropertyField(priorityProp);

        // active
        EditorGUI.BeginChangeCheck();
        EditorGUILayout.PropertyField(activeProp, new GUIContent("Active"));
        if (EditorGUI.EndChangeCheck())
        {
            foreach (Object obj in serializedObject.targetObjects)
            {
                exUIControl ctrl = obj as exUIControl;
                if (ctrl)
                {
                    ctrl.activeSelf = activeProp.boolValue;
                    EditorUtility.SetDirty(ctrl);
                }
            }
        }

        // grabMouseOrTouch
        EditorGUILayout.PropertyField(grabMouseOrTouchProp, new GUIContent("Grab Mouse Or Touch"));

        // use collider
        EditorGUI.BeginChangeCheck();
        EditorGUILayout.PropertyField(useColliderProp, new GUIContent("Use Collider"));
        if (EditorGUI.EndChangeCheck())
        {
            if (useColliderProp.boolValue)
            {
                foreach (Object obj in serializedObject.targetObjects)
                {
                    exUIControl ctrl = obj as exUIControl;
                    if (ctrl)
                    {
                        Collider collider = ctrl.GetComponent <Collider>();
                        if (collider == null)
                        {
                            collider = ctrl.gameObject.AddComponent <BoxCollider>();
                        }

                        BoxCollider boxCollider = collider as BoxCollider;
                        if (boxCollider != null)
                        {
                            Rect localRect = ctrl.GetLocalAABoundingRect();
                            boxCollider.center = new Vector3(localRect.center.x, localRect.center.y, boxCollider.center.z);
                            boxCollider.size   = new Vector3(localRect.width, localRect.height, boxCollider.size.z);
                        }
                    }
                }
            }
            else
            {
                foreach (Object obj in serializedObject.targetObjects)
                {
                    exUIControl ctrl = obj as exUIControl;
                    if (ctrl)
                    {
                        Collider[] colliders = ctrl.GetComponents <Collider>();
                        for (int i = 0; i < colliders.Length; ++i)
                        {
                            Object.DestroyImmediate(colliders[i]);
                        }
                    }
                }
            }
        }

        if (useColliderProp.boolValue)
        {
            EditorGUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            if (GUILayout.Button("Sync Collider", GUILayout.MinWidth(50), GUILayout.Height(20)))
            {
                foreach (Object obj in serializedObject.targetObjects)
                {
                    exUIControl ctrl = obj as exUIControl;
                    if (ctrl)
                    {
                        BoxCollider boxCollider = ctrl.GetComponent <BoxCollider>();
                        Rect        localRect   = ctrl.GetLocalAABoundingRect();
                        boxCollider.center = new Vector3(localRect.center.x, localRect.center.y, boxCollider.center.z);
                        boxCollider.size   = new Vector3(localRect.width, localRect.height, boxCollider.size.z);
                    }
                }
            }
            EditorGUILayout.EndHorizontal();
        }

        if (serializedObject.isEditingMultipleObjects == false)
        {
            exUIControl uiControl = target as exUIControl;

            // event adding selector
            List <string> eventDefNameList = new List <string>();
            eventDefNameList.Add("Event List");
            eventDefNameList.AddRange(uiControl.GetEventNames());

            foreach (exUIControl.EventTrigger eventTrigger in uiControl.events)
            {
                int idx = eventDefNameList.IndexOf(eventTrigger.name);
                if (idx != -1)
                {
                    eventDefNameList.RemoveAt(idx);
                }
            }

            int choice = EditorGUILayout.Popup("Add Event", 0, eventDefNameList.ToArray());
            if (choice != 0)
            {
                exUIControl.EventTrigger newTrigger = new exUIControl.EventTrigger(eventDefNameList[choice]);
                uiControl.events.Add(newTrigger);
                EditorUtility.SetDirty(target);
            }

            // event triggers
            for (int i = 0; i < uiControl.events.Count; ++i)
            {
                EditorGUILayout.Space();

                exUIControl.EventTrigger eventTrigger = uiControl.events[i];
                if (EventField(eventTrigger))
                {
                    uiControl.events.RemoveAt(i);
                    --i;
                    EditorUtility.SetDirty(target);
                }

                EditorGUILayout.Space();
            }
        }

        EditorGUILayout.Space();
    }
Пример #14
0
    ///////////////////////////////////////////////////////////////////////////////
    // functions
    ///////////////////////////////////////////////////////////////////////////////
    // ------------------------------------------------------------------
    // Desc:
    // ------------------------------------------------------------------
    protected void OnEnable()
    {
        if ( target != editPlane ) {
            editPlane = target as exPlane;

            if ( editPlane.renderer != null ) {
                EditorUtility.SetSelectedWireframeHidden(editPlane.renderer, true);
                // EditorUtility.SetSelectedWireframeHidden(editPlane.renderer, false); // DEBUG
            }

            // get trans2d
            if ( editPlane.GetComponent<exScreenPosition>() != null ) {
                trans2d = Transform2D.Screen;
            }
            else if ( editPlane.GetComponent<exViewportPosition>() != null ) {
                trans2d = Transform2D.Viewport;
            }
            else {
                trans2d = Transform2D.None;
            }
        }
    }