public void Add(ConstraintStack cstack)
 {
     if (!cstackCont.ContainsKey(cstack))
     {
         cstackCont.Add(cstack, false); //value is omitted
         //Dbg.Log("ConstraintManager.Add: {0}", cstack.name);
     }
 }
Ejemplo n.º 2
0
 public virtual void DoAwake()
 {
     if (m_tr == null)
     {
         m_tr = transform;
     }
     if (m_cstack == null)
     {
         m_cstack = m_tr.ForceGetComponent <ConstraintStack>();
         m_cstack.Add(this); //will ignore repetitive object
     }
 }
Ejemplo n.º 3
0
        // public method

        public static int RemoveByType(GameObject go, Type tp)
        {
            ConstraintStack cs = go.GetComponent <ConstraintStack>();

            if (cs)
            {
                return(cs.RemoveByType(tp));
            }
            else
            {
                return(0);
            }
        }
        // public method

        #endregion "public method"

        #region "private method"

        private static void _FoldComponents(ConstraintStack cstack)
        {
            EUtil.FoldInspectorComponents(cstack.gameObject, FoldIgnoreComponents);
            //Transform tr = cstack.transform;
            //var insWnd = EditorWindow.focusedWindow;
            //ActiveEditorTracker tracker = (ActiveEditorTracker)RCall.CallMtd("UnityEditor.InspectorWindow", "GetTracker", insWnd, null);
            //var editors = tracker.activeEditors;
            //for (int eidx = 0; eidx < editors.Length; ++eidx)
            //{
            //    var e = editors[eidx];
            //    bool shouldOpen = (e.target == cstack || e.target == tr);
            //    tracker.SetVisible(eidx, shouldOpen ? 1 : 0); //fold
            //    //RCall.CallMtd("UnityEditor.Editor", "InternalSetHidden", e, true); //hide
            //}
        }
 public void SetConstraintStack(ConstraintStack cstack)
 {
     m_cstack = cstack;
 }
        public override void OnInspectorGUI()
        {
            ConstraintStack cstack = (ConstraintStack)target;

            serializedObject.Update();

            GUILayout.Space(3f);

            // constraints
            for (int i = 0; i < cstack.constraintCount; ++i)
            {
                BaseConstraint c = cstack.Get(i);
                if (!c)
                { //remove broken reference
                    cstack.RemoveAt(i);
                    --i;
                    continue;
                }

                // draw constraint & buttons
                EditorGUILayout.BeginHorizontal();
                {
                    Color btnColor = c.IsActiveConstraint ? Color.white : Color.red;
                    EUtil.PushBackgroundColor(btnColor);
                    var  content = new GUIContent(c.GetType().Name, "Click to fold other components");
                    Rect rc      = GUILayoutUtility.GetRect(content, EditorStyles.toolbarButton);
                    if (GUI.Button(rc, content, EditorStyles.toolbarButton))
                    {
                        _FoldComponents(cstack);
                        var wnd = EditorEditorWindow.OpenWindowWithActivatorRect(c, rc);
                        EUtil.SetEditorWindowTitle(wnd, content.text);
                    }
                    EditorGUI.ProgressBar(rc, c.Influence, content.text);
                    EUtil.PopBackgroundColor();

                    if (GUILayout.Button(new GUIContent(c.IsActiveConstraint ? EConUtil.activeBtn : EConUtil.inactiveBtn, "Toggle constraint active state"), EditorStyles.toolbarButton, GUILayout.Height(20), GUILayout.Width(20)))
                    {
                        c.IsActiveConstraint = !c.IsActiveConstraint;
                        EditorUtility.SetDirty(cstack);
                    }

                    EUtil.PushGUIEnable(i != 0);
                    if (GUILayout.Button(new GUIContent(EConUtil.upBtn, "move up"), EditorStyles.toolbarButton, GUILayout.Height(20), GUILayout.Width(20)))
                    {
                        cstack.Swap(i, i - 1);
                        EditorUtility.SetDirty(cstack);
                        //ComponentUtility.MoveComponentUp(c);
                    }
                    EUtil.PopGUIEnable();

                    EUtil.PushGUIEnable(i != cstack.constraintCount - 1);
                    if (GUILayout.Button(new GUIContent(EConUtil.downBtn, "move down"), EditorStyles.toolbarButton, GUILayout.Height(20), GUILayout.Width(20)))
                    {
                        cstack.Swap(i, i + 1);
                        EditorUtility.SetDirty(cstack);
                        //ComponentUtility.MoveComponentDown(c);
                    }
                    EUtil.PopGUIEnable();

                    if (GUILayout.Button(new GUIContent(EConUtil.deleteBtn, "delete the constraint from stack"), EditorStyles.toolbarButton, GUILayout.Height(20), GUILayout.Width(20)))
                    {
                        MUndo.RecordObject(cstack, "Remove Constraint");
                        cstack.RemoveAt(i);
                        EditorUtility.SetDirty(cstack);
                        _FoldComponents(cstack);
                        EditorGUIUtility.ExitGUI();
                    }
                }
                EditorGUILayout.EndHorizontal();
            } //for(int i=0; i<cstack.constraintCount; ++i)

            GUILayout.Space(2f);

            EditorGUI.BeginChangeCheck();
            int newOrder = EditorGUILayout.IntField(new GUIContent("Exec Order", "used to help decide evaluation order, the smaller the earlier"), cstack.ExecOrder);

            if (EditorGUI.EndChangeCheck())
            {
                cstack.ExecOrder = newOrder;
            }

            { //new constraint window
                EUtil.DrawSplitter(new Color(1, 1, 1, 0.3f));

                EditorGUILayout.BeginHorizontal();
                GUILayout.Space(15f);
                var  content = new GUIContent("Add Constraint", "Add new constraint into current stack");
                Rect btnRc   = GUILayoutUtility.GetRect(content, GUI.skin.button);
                if (GUI.Button(btnRc, content))
                {
                    var  wnd   = ScriptableObject.CreateInstance <ConstraintsWindow>();
                    Rect wndRc = EUtil.GetRectByActivatorRect(wnd.position, btnRc);
                    wnd.position = wndRc;
                    wnd.SetConstraintStack(cstack);
                    wnd.ShowPopup();
                    wnd.Focus();
                }
                GUILayout.Space(15f);
                EditorGUILayout.EndHorizontal();
            }


            if (Pref.ShowInitInfos)
            {
                EditorGUILayout.PropertyField(m_spInitInfo, true);
            }



            serializedObject.ApplyModifiedProperties();
        }
 public void Remove(ConstraintStack cstack)
 {
     m_cstackCont.Remove(cstack);
     //Dbg.Log("ConstraintManager.Remove: {0}", cstack.name);
 }
Ejemplo n.º 8
0
 void Awake()
 {//to handle auto added ConstraintStack
     m_tr     = transform;
     m_cstack = m_tr.ForceGetComponent <ConstraintStack>();
     m_cstack.Add(this); //will ignore repetitive object
 }