public override void OnInspectorGUI()
        {
            MountToActor mountToActor = target as MountToActor;

            UnityEngine.Object obj = EditorGUILayout.ObjectField("Mount Actor", mountToActor.ActorGameObject, typeof(GameObject), true);
            if (obj is GameObject && (obj as GameObject) != mountToActor.ActorGameObject)
            {
                mountToActor.ActorGameObject = obj as GameObject;
            }

            string[] nodeNames;
            if (mountToActor.ActorGameObject != null)
            {
                ActorBaseComponent actorBase = mountToActor.ActorGameObject.GetComponent <ActorBaseComponent>();
                List <string>      names     = new List <string>();
                if (actorBase != null && actorBase.Asset != null && actorBase.Asset.Actor == null)
                {
                    actorBase.Asset.Load();
                }


                if (actorBase != null && actorBase.Asset != null && actorBase.Asset.Actor != null)
                {
                    foreach (Nima.ActorNode node in actorBase.Asset.Actor.Nodes)
                    {
                        if (node == null)
                        {
                            continue;
                        }
                        if (names.Contains(node.Name))
                        {
                            continue;
                        }
                        names.Add(node.Name);
                    }
                    nodeNames = names.ToArray();
                }
                else
                {
                    nodeNames = null;
                }
            }
            else
            {
                nodeNames = null;
            }

            if (nodeNames != null)
            {
                int nodeIndex = Array.IndexOf <string>(nodeNames, mountToActor.NodeName);

                int idx = EditorGUILayout.Popup("Node", nodeIndex, nodeNames);
                if (idx != nodeIndex)
                {
                    mountToActor.NodeName = nodeNames[idx];
                }
                mountToActor.InheritScale    = EditorGUILayout.Toggle("Inherit Scale", mountToActor.InheritScale);
                mountToActor.InheritRotation = EditorGUILayout.Toggle("Inherit Rotation", mountToActor.InheritRotation);
                mountToActor.ScaleModifier   = EditorGUILayout.FloatField("Scale Modifier", mountToActor.ScaleModifier);
                mountToActor.UpdateMount();
            }
        }
Example #2
0
        public override void OnInspectorGUI()
        {
            ActorBaseComponent actor = serializedObject.targetObject as ActorBaseComponent;

            ActorAsset asset = EditorGUILayout.ObjectField(actor.Asset, typeof(ActorAsset), false) as ActorAsset;

            if (asset != actor.Asset)
            {
                actor.Asset = asset;
            }

            /*if(actor.Asset != null)
             * {
             *      for(int i = 0; i < actor.Asset.m_TextureMaterials.Length; i++)
             *      {
             *              Material mat = null;
             *              Material m = EditorGUILayout.ObjectField(mat, typeof(Material), false) as Material;
             *      }
             * }*/
            if (GUILayout.Button("Reload"))
            {
                actor.Reload();
                Animator animator = actor.gameObject.GetComponent <Animator>();
                if (animator != null && animator.runtimeAnimatorController as UnityEditor.Animations.AnimatorController != null)
                {
                    Importer.ReloadMecanimController(actor, animator.runtimeAnimatorController as UnityEditor.Animations.AnimatorController);
                }
            }

            if (actor is IRenderSortableComponent)
            {
                IRenderSortableComponent renderSortable        = actor as IRenderSortableComponent;
                PropertyInfo             sortingLayersProperty = typeof(InternalEditorUtility).GetProperty("sortingLayerNames", BindingFlags.Static | BindingFlags.NonPublic);
                string[] sortLayerNames = (string[])sortingLayersProperty.GetValue(null, new object[0]);

                PropertyInfo sortingLayerUniqueIDsProperty = typeof(InternalEditorUtility).GetProperty("sortingLayerUniqueIDs", BindingFlags.Static | BindingFlags.NonPublic);
                int[]        sortLayerIds = (int[])sortingLayerUniqueIDsProperty.GetValue(null, new object[0]);


                int currentlySelectedIndex = -1;
                for (int i = 0; i < sortLayerIds.Length; i++)
                {
                    if (renderSortable.SortingLayerID == sortLayerIds[i])
                    {
                        currentlySelectedIndex = i;
                    }
                }

                int displaySelectedIndex = currentlySelectedIndex;
                if (displaySelectedIndex == -1)
                {
                    // Find default layer.
                    for (int i = 0; i < sortLayerIds.Length; i++)
                    {
                        if (sortLayerIds[i] == 0)
                        {
                            displaySelectedIndex = i;
                        }
                    }
                }

                bool reload        = false;
                int  selectedIndex = EditorGUILayout.Popup("Sorting Layer", displaySelectedIndex, sortLayerNames);
                if (selectedIndex != currentlySelectedIndex)
                {
                    renderSortable.SortingLayerID = sortLayerIds[selectedIndex];
                    reload = true;
                }

                int order = EditorGUILayout.IntField("Order in Layer", renderSortable.SortingOrder);
                if (order != renderSortable.SortingOrder)
                {
                    renderSortable.SortingOrder = order;
                    reload = true;
                }

                if (reload)
                {
                    actor.Reload();
                }
            }
            ActorMecanimComponent actorMecanim = actor.gameObject.GetComponent <ActorMecanimComponent>();

            if (actorMecanim == null)
            {
                if (GUILayout.Button("Add Mecanim Components"))
                {
                    //Animator animatorComponent = actor.gameObject.AddComponent( typeof(Animator) ) as Animator;
                    /*ActorMecanimComponent mecanimComponent = */ actor.gameObject.AddComponent(typeof(ActorMecanimComponent));                     // as ActorMecanimComponent;
                }
            }
        }
        public override void OnInspectorGUI()
        {
            PlayActorAnimation playActorAnimation = target as PlayActorAnimation;

            if (playActorAnimation != null)
            {
                m_Actor = playActorAnimation.GetComponent <ActorBaseComponent>();
                List <string> names = new List <string>();
                if (m_Actor != null && m_Actor.Asset != null && m_Actor.Asset.Actor == null)
                {
                    m_Actor.Asset.Load();
                }


                if (m_Actor != null && m_Actor.Asset != null && m_Actor.Asset.Actor != null)
                {
                    foreach (Nima.Animation.ActorAnimation animation in m_Actor.Asset.Actor.Animations)
                    {
                        names.Add(animation.Name);
                    }
                    m_AnimationNames = names.ToArray();
                }
                else
                {
                    m_AnimationNames = null;
                }
            }
            else
            {
                m_AnimationNames = null;
            }

            if (m_AnimationNames != null)
            {
                bool animationLoop  = playActorAnimation.Loop;
                int  animationIndex = Array.IndexOf <string>(m_AnimationNames, playActorAnimation.AnimationName);
                playActorAnimation.Offset = EditorGUILayout.Slider("Offset", playActorAnimation.Offset, 0.0F, 1.0F);
                playActorAnimation.Speed  = EditorGUILayout.Slider("Speed", playActorAnimation.Speed, 0.01F, 3.0F);

                int idx = EditorGUILayout.Popup(animationIndex, m_AnimationNames);
                if (idx != animationIndex)
                {
                    playActorAnimation.AnimationName = m_AnimationNames[idx];
                }
                bool loop = EditorGUILayout.Toggle("Loop", animationLoop);
                if (loop != animationLoop)
                {
                    playActorAnimation.Loop = loop;
                }
            }

            /*if(testProp == null)
             * {
             *      Debug.Log("NULL!?");
             * }
             * serializedObject.Update ();
             *
             * // Show the custom GUI controls.
             * EditorGUILayout.IntSlider (testProp, 0, 100, new GUIContent ("Damage"));
             *
             * // Apply changes to the serializedProperty - always do this in the end of OnInspectorGUI.
             * serializedObject.ApplyModifiedProperties ();*/
        }