Exemple #1
0
        protected PrefabBuilder DrawPrefabBuilderField(Model model, out bool isChanged)
        {
            EditorGUI.BeginChangeCheck();
            PrefabBuilder prefabBuilder = EditorGUILayout.ObjectField(new GUIContent("Prefab Builder",
                                                                                     "helps to construct output sprite object"), model.prefabBuilder, typeof(PrefabBuilder), false) as PrefabBuilder;

            isChanged = EditorGUI.EndChangeCheck();

            return(prefabBuilder);
        }
Exemple #2
0
        protected AnimationClip MakeAnimationClipsForView(bool isLooping, Sprite[] sprites, string viewName)
        {
            AnimationClip animClip = new AnimationClip
            {
                frameRate = studio.output.frameRate
            };

            if (isLooping)
            {
                AnimationClipSettings animClipSettings = AnimationUtility.GetAnimationClipSettings(animClip);
                animClipSettings.loopTime = true;
                AnimationUtility.SetAnimationClipSettings(animClip, animClipSettings);
            }

            EditorCurveBinding spriteCurveBinding;

            if (model.prefabBuilder != null)
            {
                spriteCurveBinding = model.prefabBuilder.MakeSpriteCurveBinding();
            }
            else
            {
                spriteCurveBinding = PrefabBuilder.GetDefaultSpriteCurveBinding();
            }

            ObjectReferenceKeyframe[] spriteKeyFrames = new ObjectReferenceKeyframe[sprites.Length];
            for (int i = 0; i < sprites.Length; i++)
            {
                spriteKeyFrames[i] = new ObjectReferenceKeyframe();
                float unitTime = 1f / animClip.frameRate;
                spriteKeyFrames[i].time  = studio.output.frameInterval * i * unitTime;
                spriteKeyFrames[i].value = sprites[i];
            }

            AnimationUtility.SetObjectReferenceCurve(animClip, spriteCurveBinding, spriteKeyFrames);

            string clipFilePath = Path.Combine(folderPath, fileBaseName + "_" + viewName + ".anim");

            AssetDatabase.CreateAsset(animClip, clipFilePath);

            if (animatorStates != null && studio.view.checkedSubViews.Count == animatorStates.Count)
            {
                for (int i = 0; i < studio.view.checkedSubViews.Count; ++i)
                {
                    if (studio.view.checkedSubViews[i].name == viewName)
                    {
                        animatorStates[i].motion = animClip;
                        break;
                    }
                }
            }

            return(animClip);
        }
Exemple #3
0
        protected void OnInspectorGUI_Multi()
        {
            EditorGUILayout.HelpBox("Displayed information is of the first selected model,\nbut any change affects all selected models.", MessageType.Info);

            MeshModel[] models = new MeshModel[targets.Length];

            for (int i = 0; i < models.Length; ++i)
            {
                models[i] = targets[i] as MeshModel;
            }

            MeshModel firstModel = models[0];

            bool isAllSkinnedModel = true;

            foreach (MeshModel model in models)
            {
                isAllSkinnedModel &= model.IsSkinnedModel();
            }

            bool isAllNotFixingToGround = true;

            foreach (MeshModel model in models)
            {
                isAllNotFixingToGround &= (!model.isFixingToOrigin || !model.isFixingToGround);
            }

            PivotType pivotType            = PivotType.Bottom;
            bool      isPivotTypeChanged   = false;
            bool      isGroundPivot        = false;
            bool      isGroundPivotChanged = false;

            if (isAllSkinnedModel || isAllNotFixingToGround)
            {
                EditorGUILayout.Space();

                if (isAllSkinnedModel)
                {
                    pivotType = DrawPivotTypeField(firstModel, out isPivotTypeChanged);
                }

                if (isAllNotFixingToGround)
                {
                    isGroundPivot = DrawGroundPivotField(firstModel, out isGroundPivotChanged);
                }
            }

            bool hasAllRootBone = true;

            foreach (MeshModel model in models)
            {
                hasAllRootBone &= (model.rootBoneObj != null);
            }

            bool isFixingToOrigin        = false;
            bool isFixingToOriginChanged = false;

            bool isAllFixingToOrigin     = true;
            bool isAllNotGroundPivot     = true;
            bool isFixingToGround        = false;
            bool isFixingToGroundChanged = false;

            if (isAllSkinnedModel && hasAllRootBone)
            {
                EditorGUILayout.Space();

                EditorGUILayout.LabelField("Root Bone");

                EditorGUI.indentLevel++;
                {
                    isFixingToOrigin = DrawFixToOriginField(firstModel, out isFixingToOriginChanged);

                    foreach (MeshModel model in models)
                    {
                        isAllFixingToOrigin &= model.isFixingToOrigin;
                    }
                    foreach (MeshModel model in models)
                    {
                        isAllNotGroundPivot &= !model.isGroundPivot;
                    }

                    if (isAllFixingToOrigin && isAllNotGroundPivot)
                    {
                        EditorGUI.indentLevel++;
                        isFixingToGround = DrawFixToGroundField(firstModel, out isFixingToGroundChanged);
                        EditorGUI.indentLevel--;
                    }
                }
                EditorGUI.indentLevel--;
            }

            EditorGUILayout.Space();

            bool       isSpritePrefabChanged;
            GameObject spritePrefab = DrawSpritePrefabField(firstModel, out isSpritePrefabChanged);

            bool hasAllSpritePrefab = true;

            foreach (MeshModel model in models)
            {
                hasAllSpritePrefab &= (model.spritePrefab != null);
            }

            PrefabBuilder prefabBuilder          = null;
            bool          isPrefabBuilderChanged = false;

            if (hasAllSpritePrefab)
            {
                EditorGUI.indentLevel++;
                prefabBuilder = DrawPrefabBuilderField(model, out isPrefabBuilderChanged);
                EditorGUI.indentLevel--;
            }

            EditorGUILayout.Space();

            bool   isNameSuffixChanged;
            string nameSuffix = DrawModelNameSuffix(firstModel, out isNameSuffixChanged);

            if (isNameSuffixChanged)
            {
                PathHelper.CorrectPathString(ref nameSuffix);
            }

            if (isPivotTypeChanged || isGroundPivotChanged || isFixingToOriginChanged || isFixingToGroundChanged ||
                isSpritePrefabChanged || isPrefabBuilderChanged || isNameSuffixChanged)
            {
                foreach (MeshModel model in models)
                {
                    Undo.RecordObject(model, "Mesh Model");

                    if (isAllSkinnedModel && isPivotTypeChanged)
                    {
                        model.pivotType = pivotType;
                    }
                    if (isAllNotFixingToGround && isGroundPivotChanged)
                    {
                        model.isGroundPivot = isGroundPivot;
                    }

                    if (isAllSkinnedModel && hasAllRootBone)
                    {
                        if (isFixingToOriginChanged)
                        {
                            model.isFixingToOrigin = isFixingToOrigin;
                        }
                        if (isAllFixingToOrigin && isAllNotGroundPivot && isFixingToGroundChanged)
                        {
                            model.isFixingToGround = isFixingToGround;
                        }
                    }

                    if (isSpritePrefabChanged)
                    {
                        model.spritePrefab = spritePrefab;
                    }

                    if (hasAllSpritePrefab && isPrefabBuilderChanged)
                    {
                        model.prefabBuilder = prefabBuilder;
                    }

                    if (isNameSuffixChanged)
                    {
                        model.nameSuffix = nameSuffix;
                    }
                }
            }

            Studio studio = FindObjectOfType <Studio>();

            if (studio == null)
            {
                return;
            }

            EditorGUILayout.Space();

            if (DrawingHelper.DrawWideButton("Add all to the model list"))
            {
                foreach (MeshModel model in models)
                {
                    AddToModelList(model);
                }
            }
        }
Exemple #4
0
        protected void OnInspectorGUI_Multi()
        {
            EditorGUILayout.HelpBox("Displayed information is of the first selected model,\nbut any change affects all selected models.", MessageType.Info);

            ParticleModel[] models = new ParticleModel[targets.Length];

            for (int i = 0; i < models.Length; ++i)
            {
                models[i] = targets[i] as ParticleModel;
            }

            ParticleModel firstModel = models[0];

            EditorGUILayout.Space();

            bool isGroundPivotChanged;
            bool isGroundPivot = DrawGroundPivotField(firstModel, out isGroundPivotChanged);

            EditorGUILayout.Space();

            bool isLoopingChanged;
            bool isLooping = DrawLoopingField(firstModel, out isLoopingChanged);

            bool isAllLooping = true;

            foreach (ParticleModel model in models)
            {
                isAllLooping &= model.isLooping;
            }

            bool isPrewarmChanged = false;
            bool isPrewarm        = false;

            if (isAllLooping)
            {
                EditorGUI.indentLevel++;
                isPrewarm = DrawPrewarmField(firstModel, out isPrewarmChanged);
                EditorGUI.indentLevel--;
            }

            EditorGUILayout.Space();

            bool       isSpritePrefabChanged;
            GameObject spritePrefab = DrawSpritePrefabField(firstModel, out isSpritePrefabChanged);

            bool hasAllSpritePrefab = true;

            foreach (ParticleModel model in models)
            {
                hasAllSpritePrefab &= (model.spritePrefab != null);
            }

            PrefabBuilder prefabBuilder          = null;
            bool          isPrefabBuilderChanged = false;

            if (hasAllSpritePrefab)
            {
                EditorGUI.indentLevel++;
                prefabBuilder = DrawPrefabBuilderField(model, out isPrefabBuilderChanged);
                EditorGUI.indentLevel--;
            }

            EditorGUILayout.Space();

            bool   isNameSuffixChanged;
            string nameSuffix = DrawModelNameSuffix(firstModel, out isNameSuffixChanged);

            if (isNameSuffixChanged)
            {
                PathHelper.CorrectPathString(ref nameSuffix);
            }

            if (isGroundPivotChanged || isLoopingChanged || isPrewarmChanged ||
                isSpritePrefabChanged || isPrefabBuilderChanged || isNameSuffixChanged)
            {
                foreach (ParticleModel model in models)
                {
                    Undo.RecordObject(model, "Particle Model");
                    if (isGroundPivotChanged)
                    {
                        model.isGroundPivot = isGroundPivot;
                    }
                    if (isLoopingChanged)
                    {
                        model.isLooping = isLooping;
                    }
                    if (isPrewarmChanged)
                    {
                        model.isPrewarm = isPrewarm;
                    }
                    if (isSpritePrefabChanged)
                    {
                        model.spritePrefab = spritePrefab;
                    }
                    if (hasAllSpritePrefab && isPrefabBuilderChanged)
                    {
                        model.prefabBuilder = prefabBuilder;
                    }
                    if (isNameSuffixChanged)
                    {
                        model.nameSuffix = nameSuffix;
                    }
                }
            }

            Studio studio = FindObjectOfType <Studio>();

            if (studio == null)
            {
                return;
            }

            EditorGUILayout.Space();

            if (DrawingHelper.DrawWideButton("Add all to the model list"))
            {
                foreach (ParticleModel model in models)
                {
                    AddToModelList(model);
                }
            }
        }