Exemplo n.º 1
0
 public static void RegisterSceneUndo(UnityObject target, string name)
 {
                 #if UNITY_3_0 || UNITY_4_0 || UNITY_4_0_1 || UNITY_4_1 || UNITY_4_2
     UnityUndo.RegisterSceneUndo(name);
                 #else
     UnityUndo.RegisterCompleteObjectUndo(target, name);
                 #endif
 }
Exemplo n.º 2
0
        protected void MuscleGUI()
        {
            bool flag = false;

            this.HeaderGUI("Preview", "Per-Muscle Settings");
            GUILayout.BeginVertical(AvatarMuscleEditor.styles.box, new GUILayoutOption[0]);
            for (int i = 0; i < this.m_MuscleBodyGroupToggle.Length; i++)
            {
                Rect rect         = GUILayoutUtility.GetRect(10f, 16f);
                Rect settingsRect = AvatarMuscleEditor.GetSettingsRect(rect);
                this.m_MuscleBodyGroupToggle[i] = GUI.Toggle(settingsRect, this.m_MuscleBodyGroupToggle[i], AvatarMuscleEditor.styles.muscleBodyGroup[i], EditorStyles.foldout);
                if (this.m_MuscleBodyGroupToggle[i])
                {
                    for (int j = 0; j < this.m_Muscles[i].Length; j++)
                    {
                        int num = this.m_Muscles[i][j];
                        if (num != -1 && this.m_MuscleMin[num] != null && this.m_MuscleMax[num] != null)
                        {
                            bool flag2 = this.m_MuscleToggle[num];
                            rect                     = GUILayoutUtility.GetRect(10f, (!flag2) ? 16f : 32f);
                            settingsRect             = AvatarMuscleEditor.GetSettingsRect(rect);
                            settingsRect.xMin       += 15f;
                            settingsRect.height      = 16f;
                            this.m_MuscleToggle[num] = GUI.Toggle(settingsRect, this.m_MuscleToggle[num], this.m_MuscleName[num], EditorStyles.foldout);
                            float num2 = AvatarMuscleEditor.PreviewSlider(rect, this.m_MuscleValue[num]);
                            if (this.m_MuscleValue[num] != num2)
                            {
                                Undo.RegisterCompleteObjectUndo(this, "Muscle preview");
                                this.m_FocusedMuscle    = num;
                                this.m_MuscleValue[num] = num2;
                                flag |= (base.gameObject != null);
                            }
                            if (flag2)
                            {
                                bool flag3 = false;
                                settingsRect.xMin += 15f;
                                settingsRect.y    += 16f;
                                Rect position = settingsRect;
                                if (settingsRect.width > 160f)
                                {
                                    Rect position2 = settingsRect;
                                    position2.width = 38f;
                                    EditorGUI.BeginChangeCheck();
                                    this.m_MuscleMinEdit[num] = EditorGUI.FloatField(position2, this.m_MuscleMinEdit[num]);
                                    flag3      |= EditorGUI.EndChangeCheck();
                                    position2.x = settingsRect.xMax - 38f;
                                    EditorGUI.BeginChangeCheck();
                                    this.m_MuscleMaxEdit[num] = EditorGUI.FloatField(position2, this.m_MuscleMaxEdit[num]);
                                    flag3         |= EditorGUI.EndChangeCheck();
                                    position.xMin += 43f;
                                    position.xMax -= 43f;
                                }
                                EditorGUI.BeginChangeCheck();
                                EditorGUI.MinMaxSlider(position, ref this.m_MuscleMinEdit[num], ref this.m_MuscleMaxEdit[num], -180f, 180f);
                                flag3 |= EditorGUI.EndChangeCheck();
                                if (flag3)
                                {
                                    this.m_MuscleMinEdit[num] = Mathf.Clamp(this.m_MuscleMinEdit[num], -180f, 0f);
                                    this.m_MuscleMaxEdit[num] = Mathf.Clamp(this.m_MuscleMaxEdit[num], 0f, 180f);
                                    flag |= this.UpdateMuscle(num, this.m_MuscleMinEdit[num], this.m_MuscleMaxEdit[num]);
                                }
                            }
                        }
                    }
                }
            }
            GUILayout.EndVertical();
            if (flag)
            {
                this.WritePose();
            }
        }
Exemplo n.º 3
0
 public override void OnInspectorGUI()
 {
     if (Event.current.type == EventType.ValidateCommand && Event.current.commandName == "UndoRedoPerformed")
     {
         AvatarSetupTool.TransferPoseToDescription(this.serializedObject, this.root);
         for (int index = 0; index < this.m_Bones.Length; ++index)
         {
             this.m_Bones[index].Serialize(this.serializedObject);
         }
     }
     this.UpdateSelectedBone();
     if (Event.current.type == EventType.KeyDown && (Event.current.keyCode == KeyCode.Backspace || Event.current.keyCode == KeyCode.Delete) && (AvatarMappingEditor.s_SelectedBoneIndex != -1 && AvatarMappingEditor.s_SelectedBoneIndex < this.m_Bones.Length))
     {
         Undo.RegisterCompleteObjectUndo((UnityEngine.Object) this, "Avatar mapping modified");
         AvatarSetupTool.BoneWrapper bone = this.m_Bones[AvatarMappingEditor.s_SelectedBoneIndex];
         bone.bone  = (Transform)null;
         bone.state = BoneState.None;
         bone.Serialize(this.serializedObject);
         Selection.activeTransform = (Transform)null;
         GUI.changed = true;
         Event.current.Use();
     }
     GUILayout.BeginVertical();
     EditorGUI.BeginChangeCheck();
     GUILayout.BeginVertical(string.Empty, (GUIStyle)"TE NodeBackground", new GUILayoutOption[0]);
     this.m_BodyView = AvatarControl.ShowBoneMapping(this.m_BodyView, new AvatarControl.BodyPartFeedback(this.IsValidBodyPart), this.m_Bones, this.serializedObject, this);
     this.HandleBodyView(this.m_BodyView);
     GUILayout.EndVertical();
     this.m_FoldoutScroll = GUILayout.BeginScrollView(this.m_FoldoutScroll, AvatarMappingEditor.styles.box, GUILayout.MinHeight(80f), GUILayout.MaxHeight(500f), GUILayout.ExpandHeight(true));
     this.DisplayFoldout();
     GUILayout.FlexibleSpace();
     GUILayout.EndScrollView();
     if (EditorGUI.EndChangeCheck())
     {
         this.ValidateMapping();
         SceneView.RepaintAll();
     }
     this.DisplayMappingButtons();
     GUILayout.EndVertical();
     if (GUIUtility.hotControl == 0)
     {
         this.TransferPoseIfChanged();
     }
     this.ApplyRevertGUI();
     if ((UnityEngine.Object)Selection.activeTransform != (UnityEngine.Object)null)
     {
         if ((UnityEngine.Object) this.m_CurrentTransformEditor != (UnityEngine.Object)null && this.m_CurrentTransformEditor.target != (UnityEngine.Object)Selection.activeTransform)
         {
             UnityEngine.Object.DestroyImmediate((UnityEngine.Object) this.m_CurrentTransformEditor);
         }
         if ((UnityEngine.Object) this.m_CurrentTransformEditor == (UnityEngine.Object)null)
         {
             this.m_CurrentTransformEditor = Editor.CreateEditor((UnityEngine.Object)Selection.activeTransform);
         }
         EditorGUILayout.Space();
         this.m_CurrentTransformEditorFoldout = EditorGUILayout.InspectorTitlebar(this.m_CurrentTransformEditorFoldout, (UnityEngine.Object)Selection.activeTransform, true);
         if (!this.m_CurrentTransformEditorFoldout || !((UnityEngine.Object) this.m_CurrentTransformEditor != (UnityEngine.Object)null))
         {
             return;
         }
         this.m_CurrentTransformEditor.OnInspectorGUI();
     }
     else
     {
         if (!((UnityEngine.Object) this.m_CurrentTransformEditor != (UnityEngine.Object)null))
         {
             return;
         }
         UnityEngine.Object.DestroyImmediate((UnityEngine.Object) this.m_CurrentTransformEditor);
         this.m_CurrentTransformEditor = (Editor)null;
     }
 }
Exemplo n.º 4
0
 public static void RegisterCompleteObjectUndo(UnityObject target, string name)
 {
     UnityUndo.RegisterCompleteObjectUndo(target, name);
 }
 void OnWizardCreate()
 {
     Undo.RegisterCompleteObjectUndo(terrainData, "Flatten Heightmap");
     HeightmapFilters.Flatten(terrainData, height / terrainData.size.y);
 }
Exemplo n.º 6
0
        public bool OnSceneGUI(Transform transform)
        {
            if (!m_Group.enabled)
            {
                return(m_Editing);
            }

            if (Event.current.type == EventType.Layout)
            {
                //If the group has moved / scaled since last frame need to retetra);)
                if (m_LastPosition != m_Group.transform.position ||
                    m_LastRotation != m_Group.transform.rotation ||
                    m_LastScale != m_Group.transform.localScale)
                {
                    MarkSourcePositionsDirty();
                }

                m_LastPosition = m_Group.transform.position;
                m_LastRotation = m_Group.transform.rotation;
                m_LastScale    = m_Group.transform.localScale;
            }

            //Need to cache this as select points will use it!
            var mouseUpEvent = Event.current.type == EventType.MouseUp;

            if (m_Editing)
            {
                if (PointEditor.SelectPoints(this, transform, ref m_Selection))
                {
                    Undo.RegisterCompleteObjectUndo(new Object[] { m_Group, m_SerializedSelectedProbes }, "Select Probes");
                }
            }

            //Special handling for paste (want to be able to paste when not in edit mode!)

            if ((Event.current.type == EventType.ValidateCommand || Event.current.type == EventType.ExecuteCommand) &&
                Event.current.commandName == EventCommandNames.Paste)
            {
                if (Event.current.type == EventType.ValidateCommand)
                {
                    if (CanPasteProbes())
                    {
                        Event.current.Use();
                    }
                }
                if (Event.current.type == EventType.ExecuteCommand)
                {
                    if (PasteProbes())
                    {
                        Event.current.Use();
                        m_Editing = true;
                    }
                }
            }

            if (drawTetrahedra)
            {
                DrawTetrahedra();
            }

            PointEditor.Draw(this, transform, m_Selection, true);

            if (!m_Editing)
            {
                return(m_Editing);
            }

            HandleEditMenuHotKeyCommands();

            if (m_Editing && PointEditor.MovePoints(this, transform, m_Selection))
            {
                Undo.RegisterCompleteObjectUndo(new Object[] { m_Group, m_SerializedSelectedProbes }, "Move Probes");
                if (LightProbeVisualization.dynamicUpdateLightProbes)
                {
                    MarkSourcePositionsDirty();
                }
            }

            if (m_Editing && mouseUpEvent && !LightProbeVisualization.dynamicUpdateLightProbes)
            {
                MarkSourcePositionsDirty();
            }

            return(m_Editing);
        }
Exemplo n.º 7
0
 public static void PasteToStateMachineTransitionParametersFromPasteboard(UnityEngine.Object transition, AnimatorController controller, bool conditions, bool parameters)
 {
     Undo.RegisterCompleteObjectUndo(transition, "Paste to Transition");
     Unsupported.PasteToStateMachineTransitionParametersFromPasteboardInternal(transition, controller, conditions, parameters);
 }
        public void OnGUI()
        {
            AnimationEvent[] array = null;
            if (this.m_Clip != null)
            {
                array = AnimationUtility.GetAnimationEvents(this.m_Clip);
            }
            else
            {
                if (this.m_ClipInfo != null)
                {
                    array = this.m_ClipInfo.GetEvents();
                }
            }
            if (array == null || this.eventIndex < 0 || this.eventIndex >= array.Length)
            {
                return;
            }
            GUI.changed = false;
            AnimationEvent animationEvent = array[this.eventIndex];

            if (this.m_Root)
            {
                List <string> list;
                List <Type>   list2;
                AnimationEventPopup.CollectSupportedMethods(this.m_Root, out list, out list2);
                List <string> list3 = new List <string>(list.Count);
                for (int i = 0; i < list.Count; i++)
                {
                    string str = " ( )";
                    if (list2[i] != null)
                    {
                        if (list2[i] == typeof(float))
                        {
                            str = " ( float )";
                        }
                        else
                        {
                            if (list2[i] == typeof(int))
                            {
                                str = " ( int )";
                            }
                            else
                            {
                                str = string.Format(" ( {0} )", list2[i].Name);
                            }
                        }
                    }
                    list3.Add(list[i] + str);
                }
                int count = list.Count;
                int num   = list.IndexOf(animationEvent.functionName);
                if (num == -1)
                {
                    num = list.Count;
                    list.Add(animationEvent.functionName);
                    if (string.IsNullOrEmpty(animationEvent.functionName))
                    {
                        list3.Add("(No Function Selected)");
                    }
                    else
                    {
                        list3.Add(animationEvent.functionName + " (Function Not Supported)");
                    }
                    list2.Add(null);
                }
                EditorGUIUtility.labelWidth = 130f;
                int num2 = num;
                num = EditorGUILayout.Popup("Function: ", num, list3.ToArray(), new GUILayoutOption[0]);
                if (num2 != num && num != -1 && num != count)
                {
                    animationEvent.functionName    = list[num];
                    animationEvent.stringParameter = ((!AnimationEventPopup.IsLogicGraphEvent(animationEvent)) ? string.Empty : AnimationEventPopup.GetEventNameForLogicGraphEvent(array, animationEvent));
                }
                Type type = list2[num];
                if (type != null)
                {
                    EditorGUILayout.Space();
                    if (type == typeof(AnimationEvent))
                    {
                        EditorGUILayout.PrefixLabel("Event Data");
                    }
                    else
                    {
                        EditorGUILayout.PrefixLabel("Parameters");
                    }
                    if (AnimationEventPopup.IsLogicGraphEvent(animationEvent))
                    {
                        this.DoEditLogicGraphEventParameters(animationEvent);
                    }
                    else
                    {
                        AnimationEventPopup.DoEditRegularParameters(animationEvent, type);
                    }
                }
            }
            else
            {
                animationEvent.functionName = EditorGUILayout.TextField(new GUIContent("Function"), animationEvent.functionName, new GUILayoutOption[0]);
                AnimationEventPopup.DoEditRegularParameters(animationEvent, typeof(AnimationEvent));
            }
            if (GUI.changed)
            {
                if (this.m_Clip != null)
                {
                    Undo.RegisterCompleteObjectUndo(this.m_Clip, "Animation Event Change");
                    AnimationUtility.SetAnimationEvents(this.m_Clip, array);
                }
                else
                {
                    if (this.m_ClipInfo != null)
                    {
                        this.m_ClipInfo.SetEvent(this.m_EventIndex, animationEvent);
                    }
                }
            }
        }
        public void EventLineGUI(Rect rect, AnimationWindowState state)
        {
            //  We only display and manipulate animation events from the main
            //  game object in selection.  If we ever want to update to handle
            //  a multiple selection, a single timeline might not be sufficient...
            AnimationClip clip     = state.activeAnimationClip;
            GameObject    animated = state.activeRootGameObject;

            GUI.BeginGroup(rect);
            Color backupCol = GUI.color;

            Rect eventLineRect = new Rect(0, 0, rect.width, rect.height);

            float mousePosTime = Mathf.Max(Mathf.RoundToInt(state.PixelToTime(Event.current.mousePosition.x, rect) * state.frameRate) / state.frameRate, 0.0f);

            // Draw events
            if (clip != null)
            {
                AnimationEvent[] events      = AnimationUtility.GetAnimationEvents(clip);
                Texture          eventMarker = EditorGUIUtility.IconContent("Animation.EventMarker").image;

                // Calculate rects
                Rect[] hitRects   = new Rect[events.Length];
                Rect[] drawRects  = new Rect[events.Length];
                int    shared     = 1;
                int    sharedLeft = 0;
                for (int i = 0; i < events.Length; i++)
                {
                    AnimationEvent evt = events[i];

                    if (sharedLeft == 0)
                    {
                        shared = 1;
                        while (i + shared < events.Length && events[i + shared].time == evt.time)
                        {
                            shared++;
                        }
                        sharedLeft = shared;
                    }
                    sharedLeft--;

                    // Important to take floor of positions of GUI stuff to get pixel correct alignment of
                    // stuff drawn with both GUI and Handles/GL. Otherwise things are off by one pixel half the time.
                    float keypos       = Mathf.Floor(state.FrameToPixel(evt.time * clip.frameRate, rect));
                    int   sharedOffset = 0;
                    if (shared > 1)
                    {
                        float spread = Mathf.Min((shared - 1) * (k_EventMarkerSize.x - 1), (int)(state.FrameDeltaToPixel(rect) - k_EventMarkerSize.x * 2));
                        sharedOffset = Mathf.FloorToInt(Mathf.Max(0, spread - (k_EventMarkerSize.x - 1) * (sharedLeft)));
                    }

                    Rect r = new Rect(
                        keypos + sharedOffset - k_EventMarkerSize.x / 2,
                        (rect.height - 10) * (float)(sharedLeft - shared + 1) / Mathf.Max(1, shared - 1),
                        k_EventMarkerSize.x,
                        k_EventMarkerSize.y);

                    hitRects[i]  = r;
                    drawRects[i] = r;
                }

                // Store tooptip info
                if (m_DirtyTooltip)
                {
                    if (m_HoverEvent >= 0 && m_HoverEvent < hitRects.Length)
                    {
                        m_InstantTooltipText  = AnimationWindowEventInspector.FormatEvent(animated, events[m_HoverEvent]);
                        m_InstantTooltipPoint = new Vector2(hitRects[m_HoverEvent].xMin + (int)(hitRects[m_HoverEvent].width / 2) + rect.x - 30, rect.yMax);
                    }
                    m_DirtyTooltip = false;
                }

                bool[] selectedEvents = new bool[events.Length];
                m_HasSelectedEvents = false;

                Object[] selectedObjects = Selection.objects;
                foreach (Object selectedObject in selectedObjects)
                {
                    AnimationWindowEvent awe = selectedObject as AnimationWindowEvent;
                    if (awe != null)
                    {
                        if (awe.eventIndex >= 0 && awe.eventIndex < selectedEvents.Length)
                        {
                            selectedEvents[awe.eventIndex] = true;
                            m_HasSelectedEvents            = true;
                        }
                    }
                }

                Vector2 offset = Vector2.zero;
                int     clickedIndex;
                float   startSelection, endSelection;

                // TODO: GUIStyle.none has hopping margins that need to be fixed
                HighLevelEvent hEvent = EditorGUIExt.MultiSelection(
                    rect,
                    drawRects,
                    new GUIContent(eventMarker),
                    hitRects,
                    ref selectedEvents,
                    null,
                    out clickedIndex,
                    out offset,
                    out startSelection,
                    out endSelection,
                    GUIStyle.none
                    );

                if (hEvent != HighLevelEvent.None)
                {
                    switch (hEvent)
                    {
                    case HighLevelEvent.BeginDrag:
                        m_EventsAtMouseDown = events;
                        m_EventTimes        = new float[events.Length];
                        for (int i = 0; i < events.Length; i++)
                        {
                            m_EventTimes[i] = events[i].time;
                        }
                        break;

                    case HighLevelEvent.SelectionChanged:
                        state.ClearKeySelections();
                        EditEvents(animated, clip, selectedEvents);
                        break;

                    case HighLevelEvent.Delete:
                        DeleteEvents(clip, selectedEvents);
                        break;

                    case HighLevelEvent.Copy:
                        CopyEvents(clip, selectedEvents);
                        break;

                    case HighLevelEvent.Paste:
                        PasteEvents(animated, clip, state.currentTime);
                        break;

                    case HighLevelEvent.DoubleClick:

                        if (clickedIndex != -1)
                        {
                            EditEvents(animated, clip, selectedEvents);
                        }
                        else
                        {
                            EventLineContextMenuAdd(new EventLineContextMenuObject(animated, clip, mousePosTime, -1, selectedEvents));
                        }
                        break;

                    case HighLevelEvent.Drag:
                        for (int i = events.Length - 1; i >= 0; i--)
                        {
                            if (selectedEvents[i])
                            {
                                AnimationEvent evt = m_EventsAtMouseDown[i];
                                evt.time = m_EventTimes[i] + offset.x * state.PixelDeltaToTime(rect);
                                evt.time = Mathf.Max(0.0F, evt.time);
                                evt.time = Mathf.RoundToInt(evt.time * clip.frameRate) / clip.frameRate;
                            }
                        }
                        int[] order = new int[selectedEvents.Length];
                        for (int i = 0; i < order.Length; i++)
                        {
                            order[i] = i;
                        }
                        System.Array.Sort(m_EventsAtMouseDown, order, new EventComparer());
                        bool[]  selectedOld = (bool[])selectedEvents.Clone();
                        float[] timesOld    = (float[])m_EventTimes.Clone();
                        for (int i = 0; i < order.Length; i++)
                        {
                            selectedEvents[i] = selectedOld[order[i]];
                            m_EventTimes[i]   = timesOld[order[i]];
                        }

                        // Update selection to reflect new order.
                        EditEvents(animated, clip, selectedEvents);

                        Undo.RegisterCompleteObjectUndo(clip, "Move Event");
                        AnimationUtility.SetAnimationEvents(clip, m_EventsAtMouseDown);
                        m_DirtyTooltip = true;
                        break;

                    case HighLevelEvent.ContextClick:
                        CreateContextMenu(animated, clip, events[clickedIndex].time, clickedIndex, selectedEvents);

                        // Mouse may move while context menu is open - make sure instant tooltip is handled
                        m_InstantTooltipText = null;
                        m_DirtyTooltip       = true;
                        state.Repaint();
                        break;
                    }
                }

                CheckRectsOnMouseMove(rect, events, hitRects);

                // Bring up menu when context-clicking on an empty timeline area (context-clicking on events is handled above)
                if (Event.current.type == EventType.ContextClick && eventLineRect.Contains(Event.current.mousePosition))
                {
                    Event.current.Use();
                    CreateContextMenu(animated, clip, mousePosTime, -1, selectedEvents);
                }
            }

            GUI.color = backupCol;
            GUI.EndGroup();
        }
Exemplo n.º 10
0
        public void EventLineGUI(Rect rect, AnimationWindowState state)
        {
            if (!(state.selectedItem == null))
            {
                AnimationClip animationClip  = state.selectedItem.animationClip;
                GameObject    rootGameObject = state.selectedItem.rootGameObject;
                GUI.BeginGroup(rect);
                Color color = GUI.color;
                Rect  rect2 = new Rect(0f, 0f, rect.width, rect.height);
                float time  = Mathf.Max((float)Mathf.RoundToInt(state.PixelToTime(Event.current.mousePosition.x, rect) * state.frameRate) / state.frameRate, 0f);
                if (animationClip != null)
                {
                    AnimationEvent[] animationEvents = AnimationUtility.GetAnimationEvents(animationClip);
                    Texture          image           = EditorGUIUtility.IconContent("Animation.EventMarker").image;
                    Rect[]           array           = new Rect[animationEvents.Length];
                    Rect[]           array2          = new Rect[animationEvents.Length];
                    int num  = 1;
                    int num2 = 0;
                    for (int i = 0; i < animationEvents.Length; i++)
                    {
                        AnimationEvent animationEvent = animationEvents[i];
                        if (num2 == 0)
                        {
                            num = 1;
                            while (i + num < animationEvents.Length && animationEvents[i + num].time == animationEvent.time)
                            {
                                num++;
                            }
                            num2 = num;
                        }
                        num2--;
                        float num3 = Mathf.Floor(state.FrameToPixel(animationEvent.time * animationClip.frameRate, rect));
                        int   num4 = 0;
                        if (num > 1)
                        {
                            float num5 = (float)Mathf.Min((num - 1) * (image.width - 1), (int)(state.FrameDeltaToPixel(rect) - (float)(image.width * 2)));
                            num4 = Mathf.FloorToInt(Mathf.Max(0f, num5 - (float)((image.width - 1) * num2)));
                        }
                        Rect rect3 = new Rect(num3 + (float)num4 - (float)(image.width / 2), (rect.height - 10f) * (float)(num2 - num + 1) / (float)Mathf.Max(1, num - 1), (float)image.width, (float)image.height);
                        array[i]  = rect3;
                        array2[i] = rect3;
                    }
                    if (this.m_DirtyTooltip)
                    {
                        if (this.m_HoverEvent >= 0 && this.m_HoverEvent < array.Length)
                        {
                            this.m_InstantTooltipText  = AnimationWindowEventInspector.FormatEvent(rootGameObject, animationEvents[this.m_HoverEvent]);
                            this.m_InstantTooltipPoint = new Vector2(array[this.m_HoverEvent].xMin + (float)((int)(array[this.m_HoverEvent].width / 2f)) + rect.x - 30f, rect.yMax);
                        }
                        this.m_DirtyTooltip = false;
                    }
                    bool[] array3 = new bool[animationEvents.Length];
                    UnityEngine.Object[] objects = Selection.objects;
                    UnityEngine.Object[] array4  = objects;
                    for (int j = 0; j < array4.Length; j++)
                    {
                        UnityEngine.Object   @object = array4[j];
                        AnimationWindowEvent animationWindowEvent = @object as AnimationWindowEvent;
                        if (animationWindowEvent != null)
                        {
                            if (animationWindowEvent.eventIndex >= 0 && animationWindowEvent.eventIndex < array3.Length)
                            {
                                array3[animationWindowEvent.eventIndex] = true;
                            }
                        }
                    }
                    Vector2        zero = Vector2.zero;
                    int            num6;
                    float          num7;
                    float          num8;
                    HighLevelEvent highLevelEvent = EditorGUIExt.MultiSelection(rect, array2, new GUIContent(image), array, ref array3, null, out num6, out zero, out num7, out num8, GUIStyle.none);
                    if (highLevelEvent != HighLevelEvent.None)
                    {
                        switch (highLevelEvent)
                        {
                        case HighLevelEvent.DoubleClick:
                            if (num6 != -1)
                            {
                                this.EditEvents(rootGameObject, animationClip, array3);
                            }
                            else
                            {
                                this.EventLineContextMenuAdd(new AnimationEventTimeLine.EventLineContextMenuObject(rootGameObject, animationClip, time, -1, array3));
                            }
                            break;

                        case HighLevelEvent.ContextClick:
                        {
                            GenericMenu genericMenu = new GenericMenu();
                            AnimationEventTimeLine.EventLineContextMenuObject userData = new AnimationEventTimeLine.EventLineContextMenuObject(rootGameObject, animationClip, animationEvents[num6].time, num6, array3);
                            int num9 = array3.Count((bool selected) => selected);
                            genericMenu.AddItem(new GUIContent("Add Animation Event"), false, new GenericMenu.MenuFunction2(this.EventLineContextMenuAdd), userData);
                            genericMenu.AddItem(new GUIContent((num9 <= 1) ? "Delete Animation Event" : "Delete Animation Events"), false, new GenericMenu.MenuFunction2(this.EventLineContextMenuDelete), userData);
                            genericMenu.ShowAsContext();
                            this.m_InstantTooltipText = null;
                            this.m_DirtyTooltip       = true;
                            state.Repaint();
                            break;
                        }

                        case HighLevelEvent.BeginDrag:
                            this.m_EventsAtMouseDown = animationEvents;
                            this.m_EventTimes        = new float[animationEvents.Length];
                            for (int k = 0; k < animationEvents.Length; k++)
                            {
                                this.m_EventTimes[k] = animationEvents[k].time;
                            }
                            break;

                        case HighLevelEvent.Drag:
                        {
                            for (int l = animationEvents.Length - 1; l >= 0; l--)
                            {
                                if (array3[l])
                                {
                                    AnimationEvent animationEvent2 = this.m_EventsAtMouseDown[l];
                                    animationEvent2.time = this.m_EventTimes[l] + zero.x * state.PixelDeltaToTime(rect);
                                    animationEvent2.time = Mathf.Max(0f, animationEvent2.time);
                                    animationEvent2.time = (float)Mathf.RoundToInt(animationEvent2.time * animationClip.frameRate) / animationClip.frameRate;
                                }
                            }
                            int[] array5 = new int[array3.Length];
                            for (int m = 0; m < array5.Length; m++)
                            {
                                array5[m] = m;
                            }
                            Array.Sort(this.m_EventsAtMouseDown, array5, new AnimationEventTimeLine.EventComparer());
                            bool[]  array6 = (bool[])array3.Clone();
                            float[] array7 = (float[])this.m_EventTimes.Clone();
                            for (int n = 0; n < array5.Length; n++)
                            {
                                array3[n]            = array6[array5[n]];
                                this.m_EventTimes[n] = array7[array5[n]];
                            }
                            this.EditEvents(rootGameObject, animationClip, array3);
                            Undo.RegisterCompleteObjectUndo(animationClip, "Move Event");
                            AnimationUtility.SetAnimationEvents(animationClip, this.m_EventsAtMouseDown);
                            this.m_DirtyTooltip = true;
                            break;
                        }

                        case HighLevelEvent.Delete:
                            this.DeleteEvents(animationClip, array3);
                            break;

                        case HighLevelEvent.SelectionChanged:
                            state.ClearKeySelections();
                            this.EditEvents(rootGameObject, animationClip, array3);
                            break;
                        }
                    }
                    this.CheckRectsOnMouseMove(rect, animationEvents, array);
                    if (Event.current.type == EventType.ContextClick && rect2.Contains(Event.current.mousePosition))
                    {
                        Event.current.Use();
                        GenericMenu genericMenu2 = new GenericMenu();
                        AnimationEventTimeLine.EventLineContextMenuObject userData2 = new AnimationEventTimeLine.EventLineContextMenuObject(rootGameObject, animationClip, time, -1, array3);
                        int num10 = array3.Count((bool selected) => selected);
                        genericMenu2.AddItem(new GUIContent("Add Animation Event"), false, new GenericMenu.MenuFunction2(this.EventLineContextMenuAdd), userData2);
                        if (num10 > 0)
                        {
                            genericMenu2.AddItem(new GUIContent((num10 <= 1) ? "Delete Animation Event" : "Delete Animation Events"), false, new GenericMenu.MenuFunction2(this.EventLineContextMenuDelete), userData2);
                        }
                        genericMenu2.ShowAsContext();
                    }
                }
                GUI.color = color;
                GUI.EndGroup();
            }
        }
Exemplo n.º 11
0
        protected void DisplayFoldout()
        {
            Dictionary <Transform, bool> modelBones = base.modelBones;

            EditorGUIUtility.SetIconSize(Vector2.one * 16f);
            EditorGUILayout.BeginHorizontal(new GUILayoutOption[0]);
            GUI.color = Color.grey;
            GUILayout.Label(AvatarMappingEditor.styles.dotFrameDotted.image, new GUILayoutOption[]
            {
                GUILayout.ExpandWidth(false)
            });
            GUI.color = Color.white;
            GUILayout.Label("Optional Bone", new GUILayoutOption[]
            {
                GUILayout.ExpandWidth(true)
            });
            EditorGUILayout.EndHorizontal();
            for (int i = 1; i < this.m_BodyPartToggle.Length; i++)
            {
                if (this.m_BodyPartToggle[i])
                {
                    if (AvatarMappingEditor.s_DirtySelection && !this.m_BodyPartFoldout[i])
                    {
                        for (int j = 0; j < this.m_BodyPartHumanBone[i].Length; j++)
                        {
                            int num = this.m_BodyPartHumanBone[i][j];
                            if (AvatarMappingEditor.s_SelectedBoneIndex == num)
                            {
                                this.m_BodyPartFoldout[i] = true;
                            }
                        }
                    }
                    this.m_BodyPartFoldout[i] = GUILayout.Toggle(this.m_BodyPartFoldout[i], AvatarMappingEditor.styles.BodyPartMapping[i], EditorStyles.foldout, new GUILayoutOption[0]);
                    EditorGUI.indentLevel++;
                    if (this.m_BodyPartFoldout[i])
                    {
                        for (int k = 0; k < this.m_BodyPartHumanBone[i].Length; k++)
                        {
                            int num2 = this.m_BodyPartHumanBone[i][k];
                            if (num2 != -1)
                            {
                                AvatarSetupTool.BoneWrapper boneWrapper = this.m_Bones[num2];
                                string text = boneWrapper.humanBoneName;
                                if (i == 5 || i == 6 || i == 8)
                                {
                                    text = text.Replace("Right", "");
                                }
                                if (i == 3 || i == 4 || i == 7)
                                {
                                    text = text.Replace("Left", "");
                                }
                                text = ObjectNames.NicifyVariableName(text);
                                Rect controlRect = EditorGUILayout.GetControlRect(new GUILayoutOption[0]);
                                Rect selectRect  = controlRect;
                                selectRect.width -= 15f;
                                Rect rect = new Rect(controlRect.x + EditorGUI.indent, controlRect.y - 1f, 19f, 19f);
                                boneWrapper.BoneDotGUI(rect, selectRect, num2, true, false, true, base.serializedObject, this);
                                controlRect.xMin += 19f;
                                Transform transform = EditorGUI.ObjectField(controlRect, new GUIContent(text), boneWrapper.bone, typeof(Transform), true) as Transform;
                                if (transform != boneWrapper.bone)
                                {
                                    Undo.RegisterCompleteObjectUndo(this, "Avatar mapping modified");
                                    boneWrapper.bone = transform;
                                    boneWrapper.Serialize(base.serializedObject);
                                    if (transform != null && !modelBones.ContainsKey(transform))
                                    {
                                        modelBones[transform] = true;
                                    }
                                }
                                if (!string.IsNullOrEmpty(boneWrapper.error))
                                {
                                    GUILayout.BeginHorizontal(new GUILayoutOption[0]);
                                    GUILayout.Space(EditorGUI.indent + 19f + 4f);
                                    GUILayout.Label(boneWrapper.error, AvatarMappingEditor.s_Styles.errorLabel, new GUILayoutOption[0]);
                                    GUILayout.EndHorizontal();
                                }
                            }
                        }
                    }
                    EditorGUI.indentLevel--;
                }
            }
            AvatarMappingEditor.s_DirtySelection = false;
            EditorGUIUtility.SetIconSize(Vector2.zero);
        }
Exemplo n.º 12
0
        internal static void RemoveSplatTexture(TerrainData terrainData, int index)
        {
            Undo.RegisterCompleteObjectUndo(terrainData, "Remove texture");
            int alphamapWidth  = terrainData.alphamapWidth;
            int alphamapHeight = terrainData.alphamapHeight;

            float[,,] numArray = terrainData.GetAlphamaps(0, 0, alphamapWidth, alphamapHeight);
            int length = numArray.GetLength(2);
            int num4   = length - 1;

            float[,,] map = new float[alphamapHeight, alphamapWidth, num4];
            for (int i = 0; i < alphamapHeight; i++)
            {
                for (int n = 0; n < alphamapWidth; n++)
                {
                    for (int num7 = 0; num7 < index; num7++)
                    {
                        map[i, n, num7] = numArray[i, n, num7];
                    }
                    for (int num8 = index + 1; num8 < length; num8++)
                    {
                        map[i, n, num8 - 1] = numArray[i, n, num8];
                    }
                }
            }
            for (int j = 0; j < alphamapHeight; j++)
            {
                for (int num10 = 0; num10 < alphamapWidth; num10++)
                {
                    float num11 = 0f;
                    for (int num12 = 0; num12 < num4; num12++)
                    {
                        num11 += map[j, num10, num12];
                    }
                    if (num11 >= 0.01)
                    {
                        float num13 = 1f / num11;
                        for (int num14 = 0; num14 < num4; num14++)
                        {
                            float single1 = map[j, num10, num14];
                            single1[0] *= num13;
                        }
                    }
                    else
                    {
                        for (int num15 = 0; num15 < num4; num15++)
                        {
                            map[j, num10, num15] = (num15 != 0) ? 0f : 1f;
                        }
                    }
                }
            }
            SplatPrototype[] splatPrototypes = terrainData.splatPrototypes;
            SplatPrototype[] prototypeArray2 = new SplatPrototype[splatPrototypes.Length - 1];
            for (int k = 0; k < index; k++)
            {
                prototypeArray2[k] = splatPrototypes[k];
            }
            for (int m = index + 1; m < length; m++)
            {
                prototypeArray2[m - 1] = splatPrototypes[m];
            }
            terrainData.splatPrototypes = prototypeArray2;
            terrainData.SetAlphamaps(0, 0, map);
        }
Exemplo n.º 13
0
        protected void MuscleGUI()
        {
            bool flag = false;

            this.HeaderGUI("Preview", "Per-Muscle Settings");
            GUILayout.BeginVertical(styles.box, new GUILayoutOption[0]);
            for (int i = 0; i < this.m_MuscleBodyGroupToggle.Length; i++)
            {
                Rect settingsRect = GetSettingsRect(GUILayoutUtility.GetRect((float)10f, (float)16f));
                this.m_MuscleBodyGroupToggle[i] = GUI.Toggle(settingsRect, this.m_MuscleBodyGroupToggle[i], styles.muscleBodyGroup[i], EditorStyles.foldout);
                if (this.m_MuscleBodyGroupToggle[i])
                {
                    for (int j = 0; j < this.m_Muscles[i].Length; j++)
                    {
                        int index = this.m_Muscles[i][j];
                        if (((index != -1) && (this.m_MuscleMin[index] != null)) && (this.m_MuscleMax[index] != null))
                        {
                            bool flag2          = this.m_MuscleToggle[index];
                            Rect wholeWidthRect = GUILayoutUtility.GetRect(10f, !flag2 ? 16f : 32f);
                            settingsRect               = GetSettingsRect(wholeWidthRect);
                            settingsRect.xMin         += 15f;
                            settingsRect.height        = 16f;
                            this.m_MuscleToggle[index] = GUI.Toggle(settingsRect, this.m_MuscleToggle[index], this.m_MuscleName[index], EditorStyles.foldout);
                            float num5 = PreviewSlider(wholeWidthRect, this.m_MuscleValue[index]);
                            if (this.m_MuscleValue[index] != num5)
                            {
                                Undo.RegisterCompleteObjectUndo(this, "Muscle preview");
                                this.m_FocusedMuscle      = index;
                                this.m_MuscleValue[index] = num5;
                                flag |= base.gameObject != null;
                            }
                            if (flag2)
                            {
                                bool flag3 = false;
                                settingsRect.xMin += 15f;
                                settingsRect.y    += 16f;
                                Rect position = settingsRect;
                                if (settingsRect.width > 160f)
                                {
                                    Rect rect4 = settingsRect;
                                    rect4.width = 38f;
                                    EditorGUI.BeginChangeCheck();
                                    this.m_MuscleMinEdit[index] = EditorGUI.FloatField(rect4, this.m_MuscleMinEdit[index]);
                                    flag3  |= EditorGUI.EndChangeCheck();
                                    rect4.x = settingsRect.xMax - 38f;
                                    EditorGUI.BeginChangeCheck();
                                    this.m_MuscleMaxEdit[index] = EditorGUI.FloatField(rect4, this.m_MuscleMaxEdit[index]);
                                    flag3         |= EditorGUI.EndChangeCheck();
                                    position.xMin += 43f;
                                    position.xMax -= 43f;
                                }
                                EditorGUI.BeginChangeCheck();
                                EditorGUI.MinMaxSlider(position, ref this.m_MuscleMinEdit[index], ref this.m_MuscleMaxEdit[index], -180f, 180f);
                                if (flag3 | EditorGUI.EndChangeCheck())
                                {
                                    this.m_MuscleMinEdit[index] = Mathf.Clamp(this.m_MuscleMinEdit[index], -180f, 0f);
                                    this.m_MuscleMaxEdit[index] = Mathf.Clamp(this.m_MuscleMaxEdit[index], 0f, 180f);
                                    flag |= this.UpdateMuscle(index, this.m_MuscleMinEdit[index], this.m_MuscleMaxEdit[index]);
                                }
                            }
                        }
                    }
                }
            }
            GUILayout.EndVertical();
            if (flag)
            {
                this.WritePose();
            }
        }
Exemplo n.º 14
0
        public bool OnSceneGUI(Transform transform)
        {
            if (!this.m_Group.enabled)
            {
                return(this.m_Editing);
            }
            if (Event.current.type == EventType.Layout)
            {
                if (this.m_LastPosition != this.m_Group.transform.position || this.m_LastRotation != this.m_Group.transform.rotation || this.m_LastScale != this.m_Group.transform.localScale)
                {
                    this.MarkTetrahedraDirty();
                }
                this.m_LastPosition = this.m_Group.transform.position;
                this.m_LastRotation = this.m_Group.transform.rotation;
                this.m_LastScale    = this.m_Group.transform.localScale;
            }
            bool firstSelect = false;

            if (Event.current.type == EventType.MouseDown && Event.current.button == 0 && this.SelectedCount == 0)
            {
                int  num  = PointEditor.FindNearest(Event.current.mousePosition, transform, this);
                bool flag = num != -1;
                if (flag && !this.m_Editing)
                {
                    this.m_Inspector.StartEditMode();
                    this.m_Editing = true;
                    firstSelect    = true;
                }
            }
            bool flag2 = Event.current.type == EventType.MouseUp;

            if (this.m_Editing && PointEditor.SelectPoints(this, transform, ref this.m_Selection, firstSelect))
            {
                Undo.RegisterCompleteObjectUndo(new UnityEngine.Object[]
                {
                    this.m_Group,
                    this.m_SerializedSelectedProbes
                }, "Select Probes");
            }
            if ((Event.current.type == EventType.ValidateCommand || Event.current.type == EventType.ExecuteCommand) && Event.current.commandName == "Paste")
            {
                if (Event.current.type == EventType.ValidateCommand && LightProbeGroupEditor.CanPasteProbes())
                {
                    Event.current.Use();
                }
                if (Event.current.type == EventType.ExecuteCommand && this.PasteProbes())
                {
                    Event.current.Use();
                    this.m_Editing = true;
                }
            }
            if (this.drawTetrahedra)
            {
                this.DrawTetrahedra();
            }
            PointEditor.Draw(this, transform, this.m_Selection, true);
            if (!this.m_Editing)
            {
                return(this.m_Editing);
            }
            this.HandleEditMenuHotKeyCommands();
            if (this.m_Editing && PointEditor.MovePoints(this, transform, this.m_Selection))
            {
                Undo.RegisterCompleteObjectUndo(new UnityEngine.Object[]
                {
                    this.m_Group,
                    this.m_SerializedSelectedProbes
                }, "Move Probes");
                if (LightmapVisualization.dynamicUpdateLightProbes)
                {
                    this.MarkTetrahedraDirty();
                }
            }
            if (this.m_Editing && flag2 && !LightmapVisualization.dynamicUpdateLightProbes)
            {
                this.MarkTetrahedraDirty();
            }
            return(this.m_Editing);
        }
Exemplo n.º 15
0
        protected void DisplayFoldout()
        {
            Dictionary <Transform, bool> modelBones = this.modelBones;

            EditorGUIUtility.SetIconSize(Vector2.one * 16f);
            EditorGUILayout.BeginHorizontal();
            GUI.color = Color.grey;
            GUILayout.Label(AvatarMappingEditor.styles.dotFrameDotted.image, new GUILayoutOption[1]
            {
                GUILayout.ExpandWidth(false)
            });
            GUI.color = Color.white;
            GUILayout.Label("Optional Bone", new GUILayoutOption[1]
            {
                GUILayout.ExpandWidth(true)
            });
            EditorGUILayout.EndHorizontal();
            for (int index1 = 1; index1 < this.m_BodyPartToggle.Length; ++index1)
            {
                if (this.m_BodyPartToggle[index1])
                {
                    if (AvatarMappingEditor.s_DirtySelection && !this.m_BodyPartFoldout[index1])
                    {
                        for (int index2 = 0; index2 < this.m_BodyPartHumanBone[index1].Length; ++index2)
                        {
                            int num = this.m_BodyPartHumanBone[index1][index2];
                            if (AvatarMappingEditor.s_SelectedBoneIndex == num)
                            {
                                this.m_BodyPartFoldout[index1] = true;
                            }
                        }
                    }
                    this.m_BodyPartFoldout[index1] = GUILayout.Toggle(this.m_BodyPartFoldout[index1], AvatarMappingEditor.styles.BodyPartMapping[index1], EditorStyles.foldout, new GUILayoutOption[0]);
                    ++EditorGUI.indentLevel;
                    if (this.m_BodyPartFoldout[index1])
                    {
                        for (int index2 = 0; index2 < this.m_BodyPartHumanBone[index1].Length; ++index2)
                        {
                            int boneIndex = this.m_BodyPartHumanBone[index1][index2];
                            if (boneIndex != -1)
                            {
                                AvatarSetupTool.BoneWrapper bone = this.m_Bones[boneIndex];
                                string name = bone.humanBoneName;
                                if (index1 == 5 || index1 == 6 || index1 == 8)
                                {
                                    name = name.Replace("Right", string.Empty);
                                }
                                if (index1 == 3 || index1 == 4 || index1 == 7)
                                {
                                    name = name.Replace("Left", string.Empty);
                                }
                                string text        = ObjectNames.NicifyVariableName(name);
                                Rect   controlRect = EditorGUILayout.GetControlRect();
                                Rect   selectRect  = controlRect;
                                selectRect.width -= 15f;
                                bone.HandleClickSelection(selectRect, boneIndex);
                                bone.BoneDotGUI(new Rect(controlRect.x + EditorGUI.indent, controlRect.y - 1f, 19f, 19f), boneIndex, false, false, this.serializedObject, this);
                                controlRect.xMin += 19f;
                                Transform key = EditorGUI.ObjectField(controlRect, new GUIContent(text), (UnityEngine.Object)bone.bone, typeof(Transform), true) as Transform;
                                if ((UnityEngine.Object)key != (UnityEngine.Object)bone.bone)
                                {
                                    Undo.RegisterCompleteObjectUndo((UnityEngine.Object) this, "Avatar mapping modified");
                                    bone.bone = key;
                                    bone.Serialize(this.serializedObject);
                                    if ((UnityEngine.Object)key != (UnityEngine.Object)null && !modelBones.ContainsKey(key))
                                    {
                                        modelBones[key] = true;
                                    }
                                }
                                if (!string.IsNullOrEmpty(bone.error))
                                {
                                    GUILayout.BeginHorizontal();
                                    GUILayout.Space((float)((double)EditorGUI.indent + 19.0 + 4.0));
                                    GUILayout.Label(bone.error, AvatarMappingEditor.s_Styles.errorLabel, new GUILayoutOption[0]);
                                    GUILayout.EndHorizontal();
                                }
                            }
                        }
                    }
                    --EditorGUI.indentLevel;
                }
            }
            AvatarMappingEditor.s_DirtySelection = false;
            EditorGUIUtility.SetIconSize(Vector2.zero);
        }
Exemplo n.º 16
0
        protected void PropertiesGUI()
        {
            bool flag = false;

            this.HeaderGUI(string.Empty, "Additional Settings");
            GUILayout.BeginVertical(AvatarMuscleEditor.styles.box, new GUILayoutOption[0]);
            this.m_ArmTwistFactor = EditorGUI.Slider(AvatarMuscleEditor.GetSettingsRect(), AvatarMuscleEditor.styles.armTwist, this.m_ArmTwistFactor, 0f, 1f);
            if (this.m_ArmTwistProperty.floatValue != this.m_ArmTwistFactor)
            {
                Undo.RegisterCompleteObjectUndo(this, "Upper arm twist");
                this.m_ArmTwistProperty.floatValue = this.m_ArmTwistFactor;
                this.UpdateAvatarParameter(HumanParameter.UpperArmTwist, this.m_ArmTwistFactor);
                flag = true;
            }
            this.m_ForeArmTwistFactor = EditorGUI.Slider(AvatarMuscleEditor.GetSettingsRect(), AvatarMuscleEditor.styles.foreArmTwist, this.m_ForeArmTwistFactor, 0f, 1f);
            if (this.m_ForeArmTwistProperty.floatValue != this.m_ForeArmTwistFactor)
            {
                Undo.RegisterCompleteObjectUndo(this, "Lower arm twist");
                this.m_ForeArmTwistProperty.floatValue = this.m_ForeArmTwistFactor;
                this.UpdateAvatarParameter(HumanParameter.LowerArmTwist, this.m_ForeArmTwistFactor);
                flag = true;
            }
            this.m_UpperLegTwistFactor = EditorGUI.Slider(AvatarMuscleEditor.GetSettingsRect(), AvatarMuscleEditor.styles.upperLegTwist, this.m_UpperLegTwistFactor, 0f, 1f);
            if (this.m_UpperLegTwistProperty.floatValue != this.m_UpperLegTwistFactor)
            {
                Undo.RegisterCompleteObjectUndo(this, "Upper leg twist");
                this.m_UpperLegTwistProperty.floatValue = this.m_UpperLegTwistFactor;
                this.UpdateAvatarParameter(HumanParameter.UpperLegTwist, this.m_UpperLegTwistFactor);
                flag = true;
            }
            this.m_LegTwistFactor = EditorGUI.Slider(AvatarMuscleEditor.GetSettingsRect(), AvatarMuscleEditor.styles.legTwist, this.m_LegTwistFactor, 0f, 1f);
            if (this.m_LegTwistProperty.floatValue != this.m_LegTwistFactor)
            {
                Undo.RegisterCompleteObjectUndo(this, "Lower leg twist");
                this.m_LegTwistProperty.floatValue = this.m_LegTwistFactor;
                this.UpdateAvatarParameter(HumanParameter.LowerLegTwist, this.m_LegTwistFactor);
                flag = true;
            }
            this.m_ArmStretchFactor = EditorGUI.Slider(AvatarMuscleEditor.GetSettingsRect(), AvatarMuscleEditor.styles.armStretch, this.m_ArmStretchFactor, 0f, 1f);
            if (this.m_ArmStretchProperty.floatValue != this.m_ArmStretchFactor)
            {
                Undo.RegisterCompleteObjectUndo(this, "Arm stretch");
                this.m_ArmStretchProperty.floatValue = this.m_ArmStretchFactor;
                this.UpdateAvatarParameter(HumanParameter.ArmStretch, this.m_ArmStretchFactor);
                flag = true;
            }
            this.m_LegStretchFactor = EditorGUI.Slider(AvatarMuscleEditor.GetSettingsRect(), AvatarMuscleEditor.styles.legStretch, this.m_LegStretchFactor, 0f, 1f);
            if (this.m_LegStretchProperty.floatValue != this.m_LegStretchFactor)
            {
                Undo.RegisterCompleteObjectUndo(this, "Leg stretch");
                this.m_LegStretchProperty.floatValue = this.m_LegStretchFactor;
                this.UpdateAvatarParameter(HumanParameter.LegStretch, this.m_LegStretchFactor);
                flag = true;
            }
            this.m_FeetSpacingFactor = EditorGUI.Slider(AvatarMuscleEditor.GetSettingsRect(), AvatarMuscleEditor.styles.feetSpacing, this.m_FeetSpacingFactor, 0f, 1f);
            if (this.m_FeetSpacingProperty.floatValue != this.m_FeetSpacingFactor)
            {
                Undo.RegisterCompleteObjectUndo(this, "Feet spacing");
                this.m_FeetSpacingProperty.floatValue = this.m_FeetSpacingFactor;
                this.UpdateAvatarParameter(HumanParameter.FeetSpacing, this.m_FeetSpacingFactor);
                flag = true;
            }
            this.m_HasTranslationDoF = EditorGUI.Toggle(AvatarMuscleEditor.GetSettingsRect(), AvatarMuscleEditor.styles.hasTranslationDoF, this.m_HasTranslationDoF);
            if (this.m_HasTranslationDoFProperty.boolValue != this.m_HasTranslationDoF)
            {
                Undo.RegisterCompleteObjectUndo(this, "Translation DoF");
                this.m_HasTranslationDoFProperty.boolValue = this.m_HasTranslationDoF;
            }
            GUILayout.EndVertical();
            if (flag)
            {
                this.WritePose();
            }
        }
        private void DoTimeline()
        {
            if (!m_ValidTransition)
            {
                return;
            }
            // get local durations
            float srcStateDuration   = (m_LeftStateTimeB - m_LeftStateTimeA) / (m_LeftStateWeightB - m_LeftStateWeightA);
            float dstStateDuration   = (m_RightStateTimeB - m_RightStateTimeA) / (m_RightStateWeightB - m_RightStateWeightA);
            float transitionDuration = m_Transition.duration * (m_RefTransition.hasFixedDuration ? 1.0f : srcStateDuration);

            // Set the timeline values
            m_Timeline.SrcStartTime = 0f;
            m_Timeline.SrcStopTime  = srcStateDuration;
            m_Timeline.SrcName      = m_RefSrcState.name;
            m_Timeline.HasExitTime  = m_RefTransition.hasExitTime;

            m_Timeline.srcLoop = m_SrcMotion ? m_SrcMotion.isLooping : false;
            m_Timeline.dstLoop = m_DstMotion ? m_DstMotion.isLooping : false;

            m_Timeline.TransitionStartTime = m_RefTransition.exitTime * srcStateDuration;
            m_Timeline.TransitionStopTime  = m_Timeline.TransitionStartTime + transitionDuration;

            m_Timeline.Time = m_AvatarPreview.timeControl.currentTime;

            m_Timeline.DstStartTime = m_Timeline.TransitionStartTime - m_RefTransition.offset * dstStateDuration;
            m_Timeline.DstStopTime  = m_Timeline.DstStartTime + dstStateDuration;

            m_Timeline.SampleStopTime = m_AvatarPreview.timeControl.stopTime;

            if (m_Timeline.TransitionStopTime == Mathf.Infinity)
            {
                m_Timeline.TransitionStopTime = Mathf.Min(m_Timeline.DstStopTime, m_Timeline.SrcStopTime);
            }


            m_Timeline.DstName = m_RefDstState.name;

            m_Timeline.SrcPivotList = m_SrcPivotList;
            m_Timeline.DstPivotList = m_DstPivotList;

            // Do the timeline
            Rect previewRect = EditorGUILayout.GetControlRect(false, 150, EditorStyles.label);

            EditorGUI.BeginChangeCheck();

            bool changedData = m_Timeline.DoTimeline(previewRect);

            if (EditorGUI.EndChangeCheck())
            {
                if (changedData)
                {
                    Undo.RegisterCompleteObjectUndo(m_RefTransition, "Edit Transition");
                    m_RefTransition.exitTime = m_Timeline.TransitionStartTime / m_Timeline.SrcDuration;
                    m_RefTransition.duration = m_Timeline.TransitionDuration / (m_RefTransition.hasFixedDuration ? 1.0f : m_Timeline.SrcDuration);
                    m_RefTransition.offset   = (m_Timeline.TransitionStartTime - m_Timeline.DstStartTime) / m_Timeline.DstDuration;
                }

                m_AvatarPreview.timeControl.nextCurrentTime = Mathf.Clamp(m_Timeline.Time, 0, m_AvatarPreview.timeControl.stopTime);
            }
        }
Exemplo n.º 18
0
        public void EventLineGUI(Rect rect, AnimationWindowState state)
        {
            if (state.selectedItem != null)
            {
                AnimationClip animationClip  = state.selectedItem.animationClip;
                GameObject    rootGameObject = state.selectedItem.rootGameObject;
                GUI.BeginGroup(rect);
                Color color = GUI.color;
                Rect  rect2 = new Rect(0f, 0f, rect.width, rect.height);
                float time  = Mathf.Max((float)(((float)Mathf.RoundToInt(state.PixelToTime(Event.current.mousePosition.x, rect) * state.frameRate)) / state.frameRate), (float)0f);
                if (animationClip != null)
                {
                    int              num8;
                    float            num9;
                    float            num10;
                    AnimationEvent[] animationEvents = AnimationUtility.GetAnimationEvents(animationClip);
                    Texture          image           = EditorGUIUtility.IconContent("Animation.EventMarker").image;
                    Rect[]           hitPositions    = new Rect[animationEvents.Length];
                    Rect[]           positions       = new Rect[animationEvents.Length];
                    int              num2            = 1;
                    int              num3            = 0;
                    for (int i = 0; i < animationEvents.Length; i++)
                    {
                        AnimationEvent event2 = animationEvents[i];
                        if (num3 == 0)
                        {
                            num2 = 1;
                            while (((i + num2) < animationEvents.Length) && (animationEvents[i + num2].time == event2.time))
                            {
                                num2++;
                            }
                            num3 = num2;
                        }
                        num3--;
                        float num5 = Mathf.Floor(state.FrameToPixel(event2.time * animationClip.frameRate, rect));
                        int   num6 = 0;
                        if (num2 > 1)
                        {
                            float num7 = Mathf.Min((int)((num2 - 1) * (image.width - 1)), (int)(((int)state.FrameDeltaToPixel(rect)) - (image.width * 2)));
                            num6 = Mathf.FloorToInt(Mathf.Max((float)0f, (float)(num7 - ((image.width - 1) * num3))));
                        }
                        Rect rect3 = new Rect((num5 + num6) - (image.width / 2), ((rect.height - 10f) * ((num3 - num2) + 1)) / ((float)Mathf.Max(1, num2 - 1)), (float)image.width, (float)image.height);
                        hitPositions[i] = rect3;
                        positions[i]    = rect3;
                    }
                    if (this.m_DirtyTooltip)
                    {
                        if ((this.m_HoverEvent >= 0) && (this.m_HoverEvent < hitPositions.Length))
                        {
                            this.m_InstantTooltipText  = AnimationWindowEventInspector.FormatEvent(rootGameObject, animationEvents[this.m_HoverEvent]);
                            this.m_InstantTooltipPoint = new Vector2(((hitPositions[this.m_HoverEvent].xMin + ((int)(hitPositions[this.m_HoverEvent].width / 2f))) + rect.x) - 30f, rect.yMax);
                        }
                        this.m_DirtyTooltip = false;
                    }
                    if ((this.m_EventsSelected == null) || (this.m_EventsSelected.Length != animationEvents.Length))
                    {
                        this.m_EventsSelected = new bool[animationEvents.Length];
                    }
                    Vector2 zero = Vector2.zero;
                    switch (EditorGUIExt.MultiSelection(rect, positions, new GUIContent(image), hitPositions, ref this.m_EventsSelected, null, out num8, out zero, out num9, out num10, GUIStyle.none))
                    {
                    case HighLevelEvent.DoubleClick:
                        if (num8 == -1)
                        {
                            this.EventLineContextMenuAdd(new EventLineContextMenuObject(rootGameObject, animationClip, time, -1));
                            break;
                        }
                        Selection.activeObject = AnimationWindowEvent.Edit(rootGameObject, animationClip, num8);
                        break;

                    case HighLevelEvent.ContextClick:
                    {
                        GenericMenu menu = new GenericMenu();
                        EventLineContextMenuObject userData = new EventLineContextMenuObject(rootGameObject, animationClip, animationEvents[num8].time, num8);
                        menu.AddItem(new GUIContent("Edit Animation Event"), false, new GenericMenu.MenuFunction2(this.EventLineContextMenuEdit), userData);
                        menu.AddItem(new GUIContent("Add Animation Event"), false, new GenericMenu.MenuFunction2(this.EventLineContextMenuAdd), userData);
                        menu.AddItem(new GUIContent("Delete Animation Event"), false, new GenericMenu.MenuFunction2(this.EventLineContextMenuDelete), userData);
                        menu.ShowAsContext();
                        this.m_InstantTooltipText = null;
                        this.m_DirtyTooltip       = true;
                        state.Repaint();
                        break;
                    }

                    case HighLevelEvent.BeginDrag:
                        this.m_EventsAtMouseDown = animationEvents;
                        this.m_EventTimes        = new float[animationEvents.Length];
                        for (int j = 0; j < animationEvents.Length; j++)
                        {
                            this.m_EventTimes[j] = animationEvents[j].time;
                        }
                        break;

                    case HighLevelEvent.Drag:
                    {
                        for (int k = animationEvents.Length - 1; k >= 0; k--)
                        {
                            if (this.m_EventsSelected[k])
                            {
                                AnimationEvent event6 = this.m_EventsAtMouseDown[k];
                                event6.time = this.m_EventTimes[k] + (zero.x * state.PixelDeltaToTime(rect));
                                event6.time = Mathf.Max(0f, event6.time);
                                event6.time = ((float)Mathf.RoundToInt(event6.time * animationClip.frameRate)) / animationClip.frameRate;
                            }
                        }
                        int[] items = new int[this.m_EventsSelected.Length];
                        for (int m = 0; m < items.Length; m++)
                        {
                            items[m] = m;
                        }
                        Array.Sort(this.m_EventsAtMouseDown, items, new EventComparer());
                        bool[]  flagArray = (bool[])this.m_EventsSelected.Clone();
                        float[] numArray2 = (float[])this.m_EventTimes.Clone();
                        for (int n = 0; n < items.Length; n++)
                        {
                            this.m_EventsSelected[n] = flagArray[items[n]];
                            this.m_EventTimes[n]     = numArray2[items[n]];
                        }
                        Undo.RegisterCompleteObjectUndo(animationClip, "Move Event");
                        AnimationUtility.SetAnimationEvents(animationClip, this.m_EventsAtMouseDown);
                        this.m_DirtyTooltip = true;
                        break;
                    }

                    case HighLevelEvent.Delete:
                        this.DeleteEvents(animationClip, this.m_EventsSelected);
                        break;

                    case HighLevelEvent.SelectionChanged:
                        state.ClearKeySelections();
                        if (num8 != -1)
                        {
                            Selection.activeObject = AnimationWindowEvent.Edit(rootGameObject, animationClip, num8);
                        }
                        break;
                    }
                    this.CheckRectsOnMouseMove(rect, animationEvents, hitPositions);
                }
                if ((Event.current.type == EventType.ContextClick) && rect2.Contains(Event.current.mousePosition))
                {
                    Event.current.Use();
                    GenericMenu menu2 = new GenericMenu();
                    menu2.AddItem(new GUIContent("Add Animation Event"), false, new GenericMenu.MenuFunction2(this.EventLineContextMenuAdd), new EventLineContextMenuObject(rootGameObject, animationClip, time, -1));
                    menu2.ShowAsContext();
                }
                GUI.color = color;
                GUI.EndGroup();
            }
        }
Exemplo n.º 19
0
        public void OnGUI()
        {
            AnimationEvent[] events = (AnimationEvent[])null;
            if ((UnityEngine.Object) this.m_Clip != (UnityEngine.Object)null)
            {
                events = AnimationUtility.GetAnimationEvents(this.m_Clip);
            }
            else if (this.m_ClipInfo != null)
            {
                events = this.m_ClipInfo.GetEvents();
            }
            if (events == null || this.eventIndex < 0 || this.eventIndex >= events.Length)
            {
                return;
            }
            GUI.changed = false;
            AnimationEvent animationEvent = events[this.eventIndex];

            if ((bool)((UnityEngine.Object) this.m_Root))
            {
                List <string>      supportedMethods;
                List <System.Type> supportedMethodsParameter;
                AnimationEventPopup.CollectSupportedMethods(this.m_Root, out supportedMethods, out supportedMethodsParameter);
                List <string> stringList = new List <string>(supportedMethods.Count);
                for (int index = 0; index < supportedMethods.Count; ++index)
                {
                    string str = " ( )";
                    if (supportedMethodsParameter[index] != null)
                    {
                        str = supportedMethodsParameter[index] != typeof(float) ? (supportedMethodsParameter[index] != typeof(int) ? string.Format(" ( {0} )", (object)supportedMethodsParameter[index].Name) : " ( int )") : " ( float )";
                    }
                    stringList.Add(supportedMethods[index] + str);
                }
                int count         = supportedMethods.Count;
                int selectedIndex = supportedMethods.IndexOf(animationEvent.functionName);
                if (selectedIndex == -1)
                {
                    selectedIndex = supportedMethods.Count;
                    supportedMethods.Add(animationEvent.functionName);
                    if (string.IsNullOrEmpty(animationEvent.functionName))
                    {
                        stringList.Add("(No Function Selected)");
                    }
                    else
                    {
                        stringList.Add(animationEvent.functionName + " (Function Not Supported)");
                    }
                    supportedMethodsParameter.Add((System.Type)null);
                }
                EditorGUIUtility.labelWidth = 130f;
                int num    = selectedIndex;
                int index1 = EditorGUILayout.Popup("Function: ", selectedIndex, stringList.ToArray(), new GUILayoutOption[0]);
                if (num != index1 && index1 != -1 && index1 != count)
                {
                    animationEvent.functionName    = supportedMethods[index1];
                    animationEvent.stringParameter = string.Empty;
                }
                System.Type selectedParameter = supportedMethodsParameter[index1];
                if (selectedParameter != null)
                {
                    EditorGUILayout.Space();
                    if (selectedParameter == typeof(AnimationEvent))
                    {
                        EditorGUILayout.PrefixLabel("Event Data");
                    }
                    else
                    {
                        EditorGUILayout.PrefixLabel("Parameters");
                    }
                    AnimationEventPopup.DoEditRegularParameters(animationEvent, selectedParameter);
                }
            }
            else
            {
                animationEvent.functionName = EditorGUILayout.TextField(new GUIContent("Function"), animationEvent.functionName, new GUILayoutOption[0]);
                AnimationEventPopup.DoEditRegularParameters(animationEvent, typeof(AnimationEvent));
            }
            if (!GUI.changed)
            {
                return;
            }
            if ((UnityEngine.Object) this.m_Clip != (UnityEngine.Object)null)
            {
                Undo.RegisterCompleteObjectUndo((UnityEngine.Object) this.m_Clip, "Animation Event Change");
                AnimationUtility.SetAnimationEvents(this.m_Clip, events);
            }
            else
            {
                if (this.m_ClipInfo == null)
                {
                    return;
                }
                this.m_ClipInfo.SetEvent(this.m_EventIndex, animationEvent);
            }
        }
        public bool OnSceneGUI(Transform transform)
        {
            if (!m_Group.enabled)
            {
                return(m_Editing);
            }

            if (Event.current.type == EventType.Layout)
            {
                //If the group has moved / scaled since last frame need to retetra);)
                if (m_LastPosition != m_Group.transform.position ||
                    m_LastRotation != m_Group.transform.rotation ||
                    m_LastScale != m_Group.transform.localScale)
                {
                    MarkTetrahedraDirty();
                }

                m_LastPosition = m_Group.transform.position;
                m_LastRotation = m_Group.transform.rotation;
                m_LastScale    = m_Group.transform.localScale;
            }

            //See if we should enter edit mode!
            bool firstSelect = false;

            if (Event.current.type == EventType.MouseDown && Event.current.button == 0)
            {
                //We have no probes selected and have clicked the mouse... Did we click a probe
                if (SelectedCount == 0)
                {
                    var selected     = PointEditor.FindNearest(Event.current.mousePosition, transform, this);
                    var clickedProbe = selected != -1;

                    if (clickedProbe && !m_Editing)
                    {
                        m_Inspector.StartEditMode();
                        m_Editing   = true;
                        firstSelect = true;
                    }
                }
            }

            //Need to cache this as select points will use it!
            var mouseUpEvent = Event.current.type == EventType.MouseUp;

            if (m_Editing)
            {
                if (PointEditor.SelectPoints(this, transform, ref m_Selection, firstSelect))
                {
                    Undo.RegisterCompleteObjectUndo(new Object[] { m_Group, m_SerializedSelectedProbes }, "Select Probes");
                }
            }

            //Special handling for paste (want to be able to paste when not in edit mode!)

            if ((Event.current.type == EventType.ValidateCommand || Event.current.type == EventType.ExecuteCommand) &&
                Event.current.commandName == EventCommandNames.Paste)
            {
                if (Event.current.type == EventType.ValidateCommand)
                {
                    if (CanPasteProbes())
                    {
                        Event.current.Use();
                    }
                }
                if (Event.current.type == EventType.ExecuteCommand)
                {
                    if (PasteProbes())
                    {
                        Event.current.Use();
                        m_Editing = true;
                    }
                }
            }

            if (drawTetrahedra)
            {
                DrawTetrahedra();
            }

            PointEditor.Draw(this, transform, m_Selection, true);

            if (!m_Editing)
            {
                return(m_Editing);
            }

            HandleEditMenuHotKeyCommands();

            if (m_Editing && PointEditor.MovePoints(this, transform, m_Selection))
            {
                Undo.RegisterCompleteObjectUndo(new Object[] { m_Group, m_SerializedSelectedProbes }, "Move Probes");
                if (LightProbeVisualization.dynamicUpdateLightProbes)
                {
                    MarkTetrahedraDirty();
                }
            }

            if (m_Editing && mouseUpEvent && !LightProbeVisualization.dynamicUpdateLightProbes)
            {
                MarkTetrahedraDirty();
            }

            return(m_Editing);
        }
Exemplo n.º 21
0
 private void OnWizardCreate()
 {
     Undo.RegisterCompleteObjectUndo(base.terrainData, "Flatten Heightmap");
     HeightmapFilters.Flatten(base.terrainData, this.height / base.terrainData.size.y);
 }
Exemplo n.º 22
0
        internal static void RemoveTerrainLayer(Terrain terrain, int index)
        {
            var terrainData = terrain.terrainData;

            Undo.RegisterCompleteObjectUndo(terrainData, "Remove terrain layer");

            int width  = terrainData.alphamapWidth;
            int height = terrainData.alphamapHeight;

            float[,,] alphamap = terrainData.GetAlphamaps(0, 0, width, height);
            int alphaCount = alphamap.GetLength(2);

            int newAlphaCount = alphaCount - 1;

            float[,,] newalphamap = new float[height, width, newAlphaCount];

            // move further alphamaps one index below
            for (int y = 0; y < height; ++y)
            {
                for (int x = 0; x < width; ++x)
                {
                    for (int a = 0; a < index; ++a)
                    {
                        newalphamap[y, x, a] = alphamap[y, x, a];
                    }
                    for (int a = index + 1; a < alphaCount; ++a)
                    {
                        newalphamap[y, x, a - 1] = alphamap[y, x, a];
                    }
                }
            }

            // normalize weights in new alpha map
            for (int y = 0; y < height; ++y)
            {
                for (int x = 0; x < width; ++x)
                {
                    float sum = 0.0F;
                    for (int a = 0; a < newAlphaCount; ++a)
                    {
                        sum += newalphamap[y, x, a];
                    }
                    if (sum >= 0.01)
                    {
                        float multiplier = 1.0F / sum;
                        for (int a = 0; a < newAlphaCount; ++a)
                        {
                            newalphamap[y, x, a] *= multiplier;
                        }
                    }
                    else
                    {
                        // in case all weights sum to pretty much zero (e.g.
                        // removing splat that had 100% weight), assign
                        // everything to 1st splat texture (just like
                        // initial terrain).
                        for (int a = 0; a < newAlphaCount; ++a)
                        {
                            newalphamap[y, x, a] = (a == 0) ? 1.0f : 0.0f;
                        }
                    }
                }
            }

            // remove splat from terrain prototypes
            var layers    = terrainData.terrainLayers;
            var newSplats = new TerrainLayer[layers.Length - 1];

            for (int a = 0; a < index; ++a)
            {
                newSplats[a] = layers[a];
            }
            for (int a = index + 1; a < alphaCount; ++a)
            {
                newSplats[a - 1] = layers[a];
            }
            terrainData.terrainLayers = newSplats;

            // set new alphamaps
            terrainData.SetAlphamaps(0, 0, newalphamap);
        }
Exemplo n.º 23
0
 public static void PasteToStateMachineFromPasteboard(AnimatorStateMachine sm, AnimatorController controller, int layerIndex, Vector3 position)
 {
     Undo.RegisterCompleteObjectUndo(sm, "Paste to StateMachine");
     PasteToStateMachineFromPasteboardInternal(sm, controller, layerIndex, position);
 }
Exemplo n.º 24
0
 public static void RegisterUndo(UnityEngine.Object[] objectsToUndo, string name)
 {
     Undo.RegisterCompleteObjectUndo(objectsToUndo, name);
 }
        protected void DisplayFoldout()
        {
            Dictionary <Transform, bool> bones = modelBones;

            EditorGUIUtility.SetIconSize(Vector2.one * 16);

            // Legend
            EditorGUILayout.BeginHorizontal();
            GUI.color = Color.grey;
            GUILayout.Label(styles.dotFrameDotted.image, GUILayout.ExpandWidth(false));
            GUI.color = Color.white;
            GUILayout.Label("Optional Bone", GUILayout.ExpandWidth(true));
            EditorGUILayout.EndHorizontal();

            // Avatar body part has nothing to show
            for (int i = 1; i < m_BodyPartToggle.Length; i++)
            {
                if (m_BodyPartToggle[i])
                {
                    //  Unfold body part ui whenever a new selection is made.
                    if ((s_DirtySelection == true) && (m_BodyPartFoldout[i] == false))
                    {
                        for (int j = 0; j < m_BodyPartHumanBone[i].Length; j++)
                        {
                            int boneIndex = m_BodyPartHumanBone[i][j];
                            if (s_SelectedBoneIndex == boneIndex)
                            {
                                m_BodyPartFoldout[i] = true;
                            }
                        }
                    }

                    m_BodyPartFoldout[i] = GUILayout.Toggle(m_BodyPartFoldout[i], styles.BodyPartMapping[i], EditorStyles.foldout);
                    EditorGUI.indentLevel++;
                    if (m_BodyPartFoldout[i])
                    {
                        for (int j = 0; j < m_BodyPartHumanBone[i].Length; j++)
                        {
                            int boneIndex = m_BodyPartHumanBone[i][j];
                            if (boneIndex == -1)
                            {
                                continue;
                            }

                            AvatarSetupTool.BoneWrapper bone = m_Bones[boneIndex];
                            string displayBoneName           = bone.humanBoneName;

                            // @TODO@MECANIM: do properly
                            if ((BodyPart)i == BodyPart.RightArm || (BodyPart)i == BodyPart.RightFingers || (BodyPart)i == BodyPart.RightLeg)
                            {
                                displayBoneName = displayBoneName.Replace("Right", "");
                            }
                            if ((BodyPart)i == BodyPart.LeftArm || (BodyPart)i == BodyPart.LeftFingers || (BodyPart)i == BodyPart.LeftLeg)
                            {
                                displayBoneName = displayBoneName.Replace("Left", "");
                            }

                            displayBoneName = ObjectNames.NicifyVariableName(displayBoneName);

                            Rect r = EditorGUILayout.GetControlRect();

                            Rect selectRect = r;
                            selectRect.width -= 15;

                            Rect rect = new Rect(r.x + EditorGUI.indent, r.y - 1, AvatarSetupTool.BoneWrapper.kIconSize, AvatarSetupTool.BoneWrapper.kIconSize);

                            bone.BoneDotGUI(rect, selectRect, boneIndex, true, false, true, serializedObject, this);
                            r.xMin += AvatarSetupTool.BoneWrapper.kIconSize;

                            Transform newBoneTransform = EditorGUI.ObjectField(r, new GUIContent(displayBoneName), bone.bone, typeof(Transform), true) as Transform;
                            if (newBoneTransform != bone.bone)
                            {
                                Undo.RegisterCompleteObjectUndo(this, "Avatar mapping modified");
                                bone.bone = newBoneTransform;
                                bone.Serialize(m_HumanBoneArray);

                                // User adding a bone manually, if it not in the modelBones dict, we must explictly add it
                                if (newBoneTransform != null && !bones.ContainsKey(newBoneTransform))
                                {
                                    bones[newBoneTransform] = true;
                                }
                            }

                            if (!string.IsNullOrEmpty(bone.error))
                            {
                                GUILayout.BeginHorizontal();
                                GUILayout.Space(EditorGUI.indent + AvatarSetupTool.BoneWrapper.kIconSize + 4);
                                GUILayout.Label(bone.error, s_Styles.errorLabel);
                                GUILayout.EndHorizontal();
                            }
                        }
                    }
                    EditorGUI.indentLevel--;
                }
            }

            s_DirtySelection = false;

            EditorGUIUtility.SetIconSize(Vector2.zero);
        }
Exemplo n.º 26
0
        internal static void RemoveSplatTexture(TerrainData terrainData, int index)
        {
            Undo.RegisterCompleteObjectUndo(terrainData, "Remove texture");
            int alphamapWidth  = terrainData.alphamapWidth;
            int alphamapHeight = terrainData.alphamapHeight;

            float[,,] alphamaps = terrainData.GetAlphamaps(0, 0, alphamapWidth, alphamapHeight);
            int length = alphamaps.GetLength(2);
            int num    = length - 1;

            float[,,] array = new float[alphamapHeight, alphamapWidth, num];
            for (int i = 0; i < alphamapHeight; i++)
            {
                for (int j = 0; j < alphamapWidth; j++)
                {
                    for (int k = 0; k < index; k++)
                    {
                        array[i, j, k] = alphamaps[i, j, k];
                    }
                    for (int l = index + 1; l < length; l++)
                    {
                        array[i, j, l - 1] = alphamaps[i, j, l];
                    }
                }
            }
            for (int m = 0; m < alphamapHeight; m++)
            {
                for (int n = 0; n < alphamapWidth; n++)
                {
                    float num2 = 0f;
                    for (int num3 = 0; num3 < num; num3++)
                    {
                        num2 += array[m, n, num3];
                    }
                    if ((double)num2 >= 0.01)
                    {
                        float num4 = 1f / num2;
                        for (int num5 = 0; num5 < num; num5++)
                        {
                            array[m, n, num5] *= num4;
                        }
                    }
                    else
                    {
                        for (int num6 = 0; num6 < num; num6++)
                        {
                            array[m, n, num6] = ((num6 != 0) ? 0f : 1f);
                        }
                    }
                }
            }
            SplatPrototype[] splatPrototypes = terrainData.splatPrototypes;
            SplatPrototype[] array2          = new SplatPrototype[splatPrototypes.Length - 1];
            for (int num7 = 0; num7 < index; num7++)
            {
                array2[num7] = splatPrototypes[num7];
            }
            for (int num8 = index + 1; num8 < length; num8++)
            {
                array2[num8 - 1] = splatPrototypes[num8];
            }
            terrainData.splatPrototypes = array2;
            terrainData.SetAlphamaps(0, 0, array);
        }
Exemplo n.º 27
0
        public void EventLineGUI(Rect rect, AnimationWindowState state)
        {
            AnimationClip activeAnimationClip  = state.activeAnimationClip;
            GameObject    activeRootGameObject = state.activeRootGameObject;

            GUI.BeginGroup(rect);
            Color color = GUI.color;
            Rect  rect1 = new Rect(0.0f, 0.0f, rect.width, rect.height);
            float time  = (float)Mathf.RoundToInt(state.PixelToTime(Event.current.mousePosition.x, rect) * state.frameRate) / state.frameRate;

            if ((UnityEngine.Object)activeAnimationClip != (UnityEngine.Object)null)
            {
                AnimationEvent[] animationEvents = AnimationUtility.GetAnimationEvents(activeAnimationClip);
                Texture          image           = EditorGUIUtility.IconContent("Animation.EventMarker").image;
                Rect[]           rectArray       = new Rect[animationEvents.Length];
                Rect[]           positions       = new Rect[animationEvents.Length];
                int num1 = 1;
                int num2 = 0;
                for (int index = 0; index < animationEvents.Length; ++index)
                {
                    AnimationEvent animationEvent = animationEvents[index];
                    if (num2 == 0)
                    {
                        num1 = 1;
                        while (index + num1 < animationEvents.Length && (double)animationEvents[index + num1].time == (double)animationEvent.time)
                        {
                            ++num1;
                        }
                        num2 = num1;
                    }
                    --num2;
                    float num3 = Mathf.Floor(state.FrameToPixel(animationEvent.time * activeAnimationClip.frameRate, rect));
                    int   num4 = 0;
                    if (num1 > 1)
                    {
                        num4 = Mathf.FloorToInt(Mathf.Max(0.0f, (float)Mathf.Min((num1 - 1) * (image.width - 1), (int)((double)state.FrameDeltaToPixel(rect) - (double)(image.width * 2))) - (float)((image.width - 1) * num2)));
                    }
                    Rect rect2 = new Rect(num3 + (float)num4 - (float)(image.width / 2), (rect.height - 10f) * (float)(num2 - num1 + 1) / (float)Mathf.Max(1, num1 - 1), (float)image.width, (float)image.height);
                    rectArray[index] = rect2;
                    positions[index] = rect2;
                }
                if (this.m_DirtyTooltip)
                {
                    if (this.m_HoverEvent >= 0 && this.m_HoverEvent < rectArray.Length)
                    {
                        this.m_InstantTooltipText  = AnimationEventPopup.FormatEvent(activeRootGameObject, animationEvents[this.m_HoverEvent]);
                        this.m_InstantTooltipPoint = new Vector2((float)((double)rectArray[this.m_HoverEvent].xMin + (double)(int)((double)rectArray[this.m_HoverEvent].width / 2.0) + (double)rect.x - 30.0), rect.yMax);
                    }
                    this.m_DirtyTooltip = false;
                }
                if (this.m_EventsSelected == null || this.m_EventsSelected.Length != animationEvents.Length)
                {
                    this.m_EventsSelected = new bool[animationEvents.Length];
                    AnimationEventPopup.ClosePopup();
                }
                Vector2 offset = Vector2.zero;
                int     clickedIndex;
                float   startSelect;
                float   endSelect;
                switch (EditorGUIExt.MultiSelection(rect, positions, new GUIContent(image), rectArray, ref this.m_EventsSelected, (bool[])null, out clickedIndex, out offset, out startSelect, out endSelect, GUIStyle.none))
                {
                case HighLevelEvent.DoubleClick:
                    if (clickedIndex != -1)
                    {
                        AnimationEventPopup.Edit(activeRootGameObject, state.activeAnimationClip, clickedIndex, this.m_Owner);
                        break;
                    }
                    this.EventLineContextMenuAdd((object)new AnimationEventTimeLine.EventLineContextMenuObject(activeRootGameObject, activeAnimationClip, time, -1));
                    break;

                case HighLevelEvent.ContextClick:
                    GenericMenu genericMenu = new GenericMenu();
                    AnimationEventTimeLine.EventLineContextMenuObject contextMenuObject = new AnimationEventTimeLine.EventLineContextMenuObject(activeRootGameObject, activeAnimationClip, animationEvents[clickedIndex].time, clickedIndex);
                    genericMenu.AddItem(new GUIContent("Edit Animation Event"), false, new GenericMenu.MenuFunction2(this.EventLineContextMenuEdit), (object)contextMenuObject);
                    genericMenu.AddItem(new GUIContent("Add Animation Event"), false, new GenericMenu.MenuFunction2(this.EventLineContextMenuAdd), (object)contextMenuObject);
                    genericMenu.AddItem(new GUIContent("Delete Animation Event"), false, new GenericMenu.MenuFunction2(this.EventLineContextMenuDelete), (object)contextMenuObject);
                    genericMenu.ShowAsContext();
                    this.m_InstantTooltipText = (string)null;
                    this.m_DirtyTooltip       = true;
                    state.Repaint();
                    break;

                case HighLevelEvent.BeginDrag:
                    this.m_EventsAtMouseDown = animationEvents;
                    this.m_EventTimes        = new float[animationEvents.Length];
                    for (int index = 0; index < animationEvents.Length; ++index)
                    {
                        this.m_EventTimes[index] = animationEvents[index].time;
                    }
                    break;

                case HighLevelEvent.Drag:
                    for (int index = animationEvents.Length - 1; index >= 0; --index)
                    {
                        if (this.m_EventsSelected[index])
                        {
                            AnimationEvent animationEvent = this.m_EventsAtMouseDown[index];
                            animationEvent.time = this.m_EventTimes[index] + offset.x * state.PixelDeltaToTime(rect);
                            animationEvent.time = Mathf.Max(0.0f, animationEvent.time);
                            animationEvent.time = (float)Mathf.RoundToInt(animationEvent.time * activeAnimationClip.frameRate) / activeAnimationClip.frameRate;
                        }
                    }
                    int[] numArray1 = new int[this.m_EventsSelected.Length];
                    for (int index = 0; index < numArray1.Length; ++index)
                    {
                        numArray1[index] = index;
                    }
                    Array.Sort((Array)this.m_EventsAtMouseDown, (Array)numArray1, (IComparer) new AnimationEventTimeLine.EventComparer());
                    bool[]  flagArray = (bool[])this.m_EventsSelected.Clone();
                    float[] numArray2 = (float[])this.m_EventTimes.Clone();
                    for (int index = 0; index < numArray1.Length; ++index)
                    {
                        this.m_EventsSelected[index] = flagArray[numArray1[index]];
                        this.m_EventTimes[index]     = numArray2[numArray1[index]];
                    }
                    Undo.RegisterCompleteObjectUndo((UnityEngine.Object)activeAnimationClip, "Move Event");
                    AnimationUtility.SetAnimationEvents(activeAnimationClip, this.m_EventsAtMouseDown);
                    this.m_DirtyTooltip = true;
                    break;

                case HighLevelEvent.Delete:
                    this.DeleteEvents(activeAnimationClip, this.m_EventsSelected);
                    break;

                case HighLevelEvent.SelectionChanged:
                    state.ClearKeySelections();
                    if (clickedIndex != -1)
                    {
                        AnimationEventPopup.UpdateSelection(activeRootGameObject, state.activeAnimationClip, clickedIndex, this.m_Owner);
                        break;
                    }
                    break;
                }
                this.CheckRectsOnMouseMove(rect, animationEvents, rectArray);
            }
            if (Event.current.type == EventType.ContextClick && rect1.Contains(Event.current.mousePosition))
            {
                Event.current.Use();
                GenericMenu genericMenu = new GenericMenu();
                genericMenu.AddItem(new GUIContent("Add Animation Event"), false, new GenericMenu.MenuFunction2(this.EventLineContextMenuAdd), (object)new AnimationEventTimeLine.EventLineContextMenuObject(activeRootGameObject, activeAnimationClip, time, -1));
                genericMenu.ShowAsContext();
            }
            GUI.color = color;
            GUI.EndGroup();
        }
Exemplo n.º 28
0
        private void AllRootCanvases()
        {
            if (VREditor.GetVREnabledOnTargetGroup(BuildPipeline.GetBuildTargetGroup(EditorUserBuildSettings.activeBuildTarget)) && (m_RenderMode.enumValueIndex == (int)RenderMode.ScreenSpaceOverlay))
            {
                EditorGUILayout.HelpBox("Using a render mode of ScreenSpaceOverlay while VR is enabled will cause the Canvas to continue to incur a rendering cost, even though the Canvas will not be visible in VR.", MessageType.Warning);
            }

            EditorGUI.BeginChangeCheck();
            EditorGUILayout.PropertyField(m_RenderMode);
            if (EditorGUI.EndChangeCheck())
            {
                var rectTransforms = targets.Select(c => (c as Canvas).transform).ToArray();
                Undo.RegisterCompleteObjectUndo(rectTransforms, "Modified RectTransform Values");
                serializedObject.ApplyModifiedProperties();
                foreach (Canvas canvas in targets)
                {
                    canvas.UpdateCanvasRectTransform(true);
                }
                GUIUtility.ExitGUI();
            }

            m_OverlayMode.target = m_RenderMode.intValue == 0;
            m_CameraMode.target  = m_RenderMode.intValue == 1;
            m_WorldMode.target   = m_RenderMode.intValue == 2;

            EditorGUI.indentLevel++;
            if (EditorGUILayout.BeginFadeGroup(m_OverlayMode.faded))
            {
                DoPixelPerfectGUIForRoot();

                EditorGUILayout.PropertyField(m_SortingOrder, Styles.sortingOrder);
                GUIContent[] displayNames = DisplayUtility.GetDisplayNames();
                EditorGUILayout.IntPopup(m_TargetDisplay, displayNames, DisplayUtility.GetDisplayIndices(), Styles.targetDisplay);
            }
            EditorGUILayout.EndFadeGroup();

            if (EditorGUILayout.BeginFadeGroup(m_CameraMode.faded))
            {
                DoPixelPerfectGUIForRoot();

                EditorGUILayout.PropertyField(m_Camera, Styles.renderCamera);

                if (m_Camera.objectReferenceValue == null)
                {
                    EditorGUILayout.HelpBox("A Screen Space Canvas with no specified camera acts like an Overlay Canvas.",
                                            MessageType.Warning);
                }

                if (m_Camera.objectReferenceValue != null)
                {
                    EditorGUILayout.PropertyField(m_PlaneDistance);
                    EditorGUILayout.PropertyField(m_UpdateRectTransformForStandalone, Styles.standaloneRenderResize);
                }

                EditorGUILayout.Space();

                if (m_Camera.objectReferenceValue != null)
                {
                    EditorGUILayout.SortingLayerField(Styles.m_SortingLayerStyle, m_SortingLayerID, EditorStyles.popup, EditorStyles.label);
                }
                EditorGUILayout.PropertyField(m_SortingOrder, Styles.m_SortingOrderStyle);
            }
            EditorGUILayout.EndFadeGroup();

            if (EditorGUILayout.BeginFadeGroup(m_WorldMode.faded))
            {
                EditorGUILayout.PropertyField(m_Camera, Styles.eventCamera);

                if (m_Camera.objectReferenceValue == null)
                {
                    EditorGUILayout.HelpBox("A World Space Canvas with no specified Event Camera may not register UI events correctly.",
                                            MessageType.Warning);
                }

                EditorGUILayout.Space();
                EditorGUILayout.SortingLayerField(Styles.m_SortingLayerStyle, m_SortingLayerID, EditorStyles.popup);
                EditorGUILayout.PropertyField(m_SortingOrder, Styles.m_SortingOrderStyle);
            }
            EditorGUILayout.EndFadeGroup();
            EditorGUI.indentLevel--;
        }