void OnEnable()
    {
        GetEditorPrefs();

        jiggleBone = (SoxAtkJiggleBone)target;

        ms_animated         = serializedObject.FindProperty("m_animated");
        ms_simType          = serializedObject.FindProperty("m_simType");
        ms_targetDistance   = serializedObject.FindProperty("m_targetDistance");
        ms_targetFlip       = serializedObject.FindProperty("m_targetFlip");
        ms_tension          = serializedObject.FindProperty("m_tension");
        ms_inercia          = serializedObject.FindProperty("m_inercia");
        ms_lookAxis         = serializedObject.FindProperty("m_lookAxis");
        ms_lookAxisFlip     = serializedObject.FindProperty("m_lookAxisFlip");
        ms_sourceUpAxis     = serializedObject.FindProperty("m_sourceUpAxis");
        ms_sourceUpAxisFlip = serializedObject.FindProperty("m_sourceUpAxisFlip");
        ms_upWorld          = serializedObject.FindProperty("m_upWorld");
        ms_upNode           = serializedObject.FindProperty("m_upNode");
        ms_upNodeAxis       = serializedObject.FindProperty("m_upNodeAxis");
        ms_upnodeControl    = serializedObject.FindProperty("m_upnodeControl");

        ms_gravity   = serializedObject.FindProperty("m_gravity");
        ms_colliders = serializedObject.FindProperty("m_colliders");

        ms_optShowGizmosAtPlaying = serializedObject.FindProperty("m_optShowGizmosAtPlaying");
        ms_optShowGizmosAtEditor  = serializedObject.FindProperty("m_optShowGizmosAtEditor");
        ms_optGizmoSize           = serializedObject.FindProperty("m_optGizmoSize");
        ms_optShowHiddenNodes     = serializedObject.FindProperty("m_optShowHiddenNodes");

        // 프로젝트 창에서 선택한 프리팹을 버전체크하면 문제가 발생한다. Selection.transforms.Length가 0이면 Project View 라는 뜻
        if (Selection.transforms.Length > 0 && Application.isPlaying && jiggleBone.gameObject.activeInHierarchy && jiggleBone.enabled)
        {
            jiggleBone.EnsureGoodVars();
        }
    }
Ejemplo n.º 2
0
    // 모든 지글본의 SetHead가 수행된 이후 불리우는 함수. 최상위 진짜 헤드를 세팅한다.
    public void SetRealHead()
    {
        int              safetyCheck = 0; // 무한루프를 위한 안전장치
        bool             found       = false;
        SoxAtkJiggleBone jiggleBone  = m_tree[0];
        SoxAtkJiggleBone realHead    = m_tree[0];

        while (!found)
        {
            if (jiggleBone.m_ifHead)
            {
                realHead = jiggleBone;
                found    = true;
            }
            else
            {
                jiggleBone = jiggleBone.m_tree[0];
                safetyCheck++;
            }

            // 십만번 이상 루프를 돌면 뭔가 문제가 있는 상황
            if (safetyCheck > 100000)
            {
                found = true;
            }
        }
        m_tree[0] = realHead;
    }
Ejemplo n.º 3
0
    // 누가 우두머리인지 결정한다. m_ifHead, m_tree 결정, Awake에서 호출됨
    private void SetHead()
    {
        // 부모가 없거나 부모 지글본이 없으면 내가 우두머리다. 아무것도 안하고 그냥 리턴
        if (meTrans.parent == null)
        {
            return;
        }
        SoxAtkJiggleBone headJiggleBone = meTrans.parent.GetComponent <SoxAtkJiggleBone>();

        if (headJiggleBone == null)
        {
            return;
        }
        // 부모 지글본이 꺼져있으면 역시 내가 우두머리다.
        if (headJiggleBone.gameObject.activeInHierarchy == false || headJiggleBone.enabled == false)
        {
            return;
        }

        // 이후 부모 지글본이 있는 경우

        // while 로 진짜 헤드 찾기. 초기화가 무작위로 되기때문에 헤드의 헤드의 헤드의 헤드가 진짜 해드일 수 있다.
        bool found = false;

        while (!found)
        {
            if (headJiggleBone.m_ifHead)
            {
                found = true;
            }
            else
            {
                // 헤드의 헤드 찾기
                headJiggleBone = headJiggleBone.m_tree[0];
            }
        }

        // 자신의 트리를 헤드 트리의 밑으로 더한다.
        // 헤드의 Start 함수가 작동 했을 수도 있고 안했을 수도 있다. m_treeInit을 검사해야함
        if (!headJiggleBone.m_treeInit)
        {
            // 초기화 안했으면 대신 초기화 해준다.
            headJiggleBone.m_tree     = new SoxAtkJiggleBone[] { headJiggleBone };
            headJiggleBone.m_treeInit = true;
        }

        headJiggleBone.m_tree = ArrayAdd(headJiggleBone.m_tree, m_tree);

        // 나는 더이상 헤드가 아니다.
        m_ifHead = false;

        // 내 헤드는 headJiggleBone이다.
        m_tree = new SoxAtkJiggleBone[] { headJiggleBone };
    }
Ejemplo n.º 4
0
    // 지글본용으로 세팅되었던 노드들을 원래대로 되돌린다.
    private void RevertNodesJigglebone()
    {
        for (int i = 0; i < m_nodes.Length; i++)
        {
            if (m_nodes[i] != null)
            {
                SoxAtkJiggleBone jiggleBone = m_nodesOriginal[i].GetComponent <SoxAtkJiggleBone>();
                if (jiggleBone != null)
                {
                    if (jiggleBone.gameObject.activeInHierarchy && jiggleBone.enabled)
                    {
                        jiggleBone.RemoveMixedTentacle();
                    }
                }
                m_nodes[i] = m_nodesOriginal[i];
            }
        }

        /* 리플랙션 방식 봉인
         * // SoxAtkJiggleBone클래스가 설치되지 않은 곳에서도 SoxAtkJiggleBone의 함수를 실행하고 값을 얻어오기 위해 리플랙션의 복잡한 과정을 거친다.
         * Type jiggleBonetype = Type.GetType("SoxAtkJiggleBone");
         * if (jiggleBonetype == null)
         *  return;  // 지글본이 없는 환경에서는 그냥 리턴
         *
         * for (int i = 0; i < m_nodes.Length; i++)
         * {
         *  m_nodes[i] = m_nodesOriginal[i];
         * }
         *
         * MethodInfo getThisEnabled = jiggleBonetype.GetMethod("GetThisEnabled");
         * MethodInfo removeMixedTentacle = jiggleBonetype.GetMethod("RemoveMixedTentacle");
         *
         * for (int i = 0; i < m_nodes.Length; i++)
         * {
         *  if (m_nodes[i] != null)
         *  {
         *      object jiggleBone = m_nodes[i].GetComponent(jiggleBonetype);
         *      if (jiggleBone != null)
         *      {
         *          if ((bool)getThisEnabled.Invoke(jiggleBone, null))
         *          {
         *              removeMixedTentacle.Invoke(jiggleBone, null);
         *          }
         *      }
         *  }
         * }
         */
    }
Ejemplo n.º 5
0
    private void SaveNodesJigglebone()
    {
        for (int i = 0; i < m_nodes.Length; i++)
        {
            if (m_nodes[i] != null)
            {
                SoxAtkJiggleBone jiggleBone = m_nodes[i].GetComponent <SoxAtkJiggleBone>();
                if (jiggleBone != null)
                {
                    if (jiggleBone.gameObject.activeInHierarchy && jiggleBone.enabled)
                    {
                        m_nodes[i] = jiggleBone.SetMixedTentacle(this);
                    }
                }
            }
        }

        /* 리플랙션으로 구현했던...
         * // SoxAtkJiggleBone클래스가 설치되지 않은 곳에서도 SoxAtkJiggleBone의 함수를 실행하고 값을 얻어오기 위해 리플랙션으로 구현했던 코드.
         * // 지글본과 텐타클의 긴밀한 통신이 필요해지면서 두 클래스가 모두 있다는 전제를 하면서 봉인
         * Type jiggleBonetype = Type.GetType("SoxAtkJiggleBone");
         * if (jiggleBonetype == null)
         *  return; // 지글본이 없는 환경에서는 그냥 리턴
         *
         * MethodInfo setMixedTentacle = jiggleBonetype.GetMethod("SetMixedTentacle");
         * MethodInfo getThisEnabled = jiggleBonetype.GetMethod("GetThisEnabled");
         *
         * for (int i = 0; i < m_nodes.Length; i++)
         * {
         *  if (m_nodes[i] != null)
         *  {
         *      object jiggleBone = m_nodes[i].GetComponent(jiggleBonetype);
         *      if (jiggleBone != null)
         *      {
         *          if ((bool)getThisEnabled.Invoke(jiggleBone, null))
         *          {
         *              Transform tentacle = (Transform)setMixedTentacle.Invoke(jiggleBone, null);
         *              if (tentacle != null)
         *                  m_nodes[i] = tentacle;
         *          }
         *      }
         *  }
         * }
         */
    }
Ejemplo n.º 6
0
    private SoxAtkJiggleBone[] ArrayAdd(SoxAtkJiggleBone[] arrA, SoxAtkJiggleBone[] arrB)
    {
        if (arrA == null && arrB != null)
        {
            return(arrB);
        }
        if (arrA != null && arrB == null)
        {
            return(arrA);
        }
        if (arrA == null && arrB == null)
        {
            return(null);
        }

        SoxAtkJiggleBone[] returnArr = new SoxAtkJiggleBone[arrA.Length + arrB.Length];
        Array.Copy(arrA, 0, returnArr, 0, arrA.Length);
        Array.Copy(arrB, 0, returnArr, arrA.Length, arrB.Length);

        return(returnArr);
    }
    public override void OnInspectorGUI()
    {
        jiggleBone = (SoxAtkJiggleBone)target;

        // GUI레이아웃 시작=======================================================
        //DrawDefaultInspector();
        Undo.RecordObject(target, "Jiggle Bone Changed Settings");
        EditorGUI.BeginChangeCheck();

        GUILayout.BeginHorizontal();
        if (GUILayout.Button("Unity 3D"))
        {
            ms_targetFlip.boolValue        = false;
            ms_lookAxis.enumValueIndex     = (int)SoxAtkJiggleBone.Axis.Z;
            ms_lookAxisFlip.boolValue      = false;
            ms_sourceUpAxis.enumValueIndex = (int)SoxAtkJiggleBone.Axis.Y;
            ms_sourceUpAxisFlip.boolValue  = false;
            //ms_upWorld.boolValue = false;
            ms_upNodeAxis.enumValueIndex = (int)SoxAtkJiggleBone.Axis.Y;
        }
        if (GUILayout.Button("3ds Max"))
        {
            ms_targetFlip.boolValue        = true;
            ms_lookAxis.enumValueIndex     = (int)SoxAtkJiggleBone.Axis.X;
            ms_lookAxisFlip.boolValue      = true;
            ms_sourceUpAxis.enumValueIndex = (int)SoxAtkJiggleBone.Axis.Z;
            ms_sourceUpAxisFlip.boolValue  = false;
            //ms_upWorld.boolValue = false;
            ms_upNodeAxis.enumValueIndex = (int)SoxAtkJiggleBone.Axis.Z;
        }
        if (GUILayout.Button("Maya"))
        {
            ms_targetFlip.boolValue        = true;
            ms_lookAxis.enumValueIndex     = (int)SoxAtkJiggleBone.Axis.X;
            ms_lookAxisFlip.boolValue      = true;
            ms_sourceUpAxis.enumValueIndex = (int)SoxAtkJiggleBone.Axis.Y;
            ms_sourceUpAxisFlip.boolValue  = false;
            //ms_upWorld.boolValue = false;
            ms_upNodeAxis.enumValueIndex = (int)SoxAtkJiggleBone.Axis.Y;
        }
        GUILayout.EndHorizontal();

        EditorGUILayout.PropertyField(ms_animated, new GUIContent("Animated", "This should only be used if Animation is active. Even if it is not Animation, it uses all the changes that operate on Update(). Please use it only when necessary, as it may affect performance."));

        EditorGUILayout.PropertyField(ms_simType, new GUIContent("Simulation Type"));

        GUILayout.BeginHorizontal();
        EditorGUILayout.PropertyField(ms_targetDistance, new GUIContent("Target Distance"));
        // PropertyField에서는 ToggleLeft를 사용할 수 없어서 LabelField를 응용해서 ToggleLeft처럼 보이게 함
        EditorGUILayout.PropertyField(ms_targetFlip, GUIContent.none, GUILayout.Width(mc_toggleSpace));
        EditorGUILayout.LabelField("Flip");
        GUILayout.EndHorizontal();

        EditorGUILayout.PropertyField(ms_tension, new GUIContent("Tension"));
        EditorGUILayout.PropertyField(ms_inercia, new GUIContent("Inercia"));

        GUILayout.BeginHorizontal();
        EditorGUILayout.PropertyField(ms_lookAxis, new GUIContent("Look Axis"));
        EditorGUILayout.PropertyField(ms_lookAxisFlip, GUIContent.none, GUILayout.Width(mc_toggleSpace));
        EditorGUILayout.LabelField("Flip");
        GUILayout.EndHorizontal();

        GUILayout.BeginHorizontal();
        EditorGUILayout.PropertyField(ms_sourceUpAxis, new GUIContent("Source Up Axis"));
        EditorGUILayout.PropertyField(ms_sourceUpAxisFlip, GUIContent.none, GUILayout.Width(mc_toggleSpace));
        EditorGUILayout.LabelField("Flip");
        GUILayout.EndHorizontal();

        EditorGUILayout.PropertyField(ms_upWorld, new GUIContent("Up World"));
        if (ms_upWorld.boolValue)
        {
            GUI.enabled = false;
        }

        EditorGUILayout.PropertyField(ms_upNode, new GUIContent("Up Node"));
        GUI.enabled = true;

        GUILayout.BeginHorizontal();
        if (jiggleBone.m_upWorld)
        {
            EditorGUILayout.PropertyField(ms_upNodeAxis, new GUIContent("Up World Axis"));
        }
        else
        {
            EditorGUILayout.PropertyField(ms_upNodeAxis, new GUIContent("Up Node Axis"));
        }
        EditorGUILayout.LabelField("");
        GUILayout.EndHorizontal();

        EditorGUILayout.PropertyField(ms_upnodeControl, new GUIContent("Upnode Control"));

        EditorGUILayout.PropertyField(ms_gravity, new GUIContent("Gravity"));

        EditorGUILayout.PropertyField(ms_colliders, new GUIContent("Colliders"), true); // true 는 includeChildren 옵션임. 시리얼라이즈 된 배열을 처리하려면 true 해줘야함

        SoxAtkJiggleBoneOptions = EditorGUILayout.Foldout(SoxAtkJiggleBoneOptions, "Debug");
        if (SoxAtkJiggleBoneOptions)
        {
            EditorGUI.indentLevel++;
            EditorGUILayout.PropertyField(ms_optShowGizmosAtPlaying, new GUIContent("Show Gizmos at Play"));
            EditorGUILayout.PropertyField(ms_optShowGizmosAtEditor, new GUIContent("Show Gizmos at Editor"));
            //ms_optGizmoSize.floatValue = EditorGUILayout.FloatField("Gizmo Size", ms_optGizmoSize.floatValue);
            EditorGUILayout.PropertyField(ms_optGizmoSize, new GUIContent("Gizmo Size"));
            if (!Application.isPlaying)
            {
                GUI.enabled = false;
            }
            EditorGUILayout.PropertyField(ms_optShowHiddenNodes, new GUIContent("Show Hidden Nodes"));
            if (jiggleBone.m_hierarchyChanged)
            {
                EditorApplication.DirtyHierarchyWindowSorting();
                jiggleBone.m_hierarchyChanged = false;
            }
            GUI.enabled = true;
            EditorGUI.indentLevel--;
        }

        serializedObject.ApplyModifiedProperties();    // 이건 시리얼 오브젝트 에디터GUI의 변화를 실제 오브젝트에 반영하는 것
        serializedObject.Update();                     // 이건 오브젝트의 변화를 에디터에 반영하는 것. 예를 들어 Undo 등의 변화라던가 Reset 버튼에 의한 변화가 있으면 업데이트 해줘야한다.

        if (EditorGUI.EndChangeCheck())
        {
            // 프로젝트 창에서 선택한 프리팹을 버전체크하면 문제가 발생한다. Selection.transforms.Length가 0이면 Project View 라는 뜻
            if (Selection.transforms.Length > 0 && Application.isPlaying && jiggleBone.gameObject.activeInHierarchy && jiggleBone.enabled)
            {
                jiggleBone.MyValidate();
            }
        }
        Undo.FlushUndoRecordObjects();

        // GUI레이아웃 끝========================================================
    } // end of OnInspectorGUI()