public override void Draw()
        {
            GUILayout.BeginArea(myRect, Title, Style);
            GUILayout.Space(5);
            GUILayout.BeginHorizontal();
            GUILayout.Space(SpacePixel);
            GUILayout.FlexibleSpace();
            GUILayout.BeginVertical();
            GUILayout.Space(SpacePixel);

            //get all character
            var list = ObjectInfoHelper.GetCharacterNames();

            //set character index if initialize request
            if (Initialize)
            {
                //find origin object
                var origin = AssetDatabase.LoadAssetAtPath(Path, typeof(GameObject)) as GameObject;

                if (origin != null)
                {
                    //set index
                    Index = list.IndexOf(list.Where(c => c == origin.name).FirstOrDefault());
                }
                Initialize = false;
            }

            //choose character
            GUILayout.BeginHorizontal();
            GUILayout.Label("Character", WhiteTxtStyle, GUILayout.Width(LabelWidth));
            Index = EditorGUILayout.Popup(Index, list.ToArray());
            GUILayout.EndHorizontal();

            //find selected character
            string path     = ValueManager.CharaPath + list[Index] + ".prefab";
            var    selected = AssetDatabase.LoadAssetAtPath(path, typeof(GameObject)) as GameObject;

            if (selected != null)
            {
                //set character path
                Path = path;
            }

            //is wait for character disappear
            GUILayout.BeginHorizontal();
            GUILayout.Label("Is wait", WhiteTxtStyle, GUILayout.Width(LabelWidth));
            IsWait = EditorGUILayout.Toggle(IsWait);
            GUILayout.EndHorizontal();

            GUILayout.EndVertical();
            GUILayout.Space(SpacePixel);
            GUILayout.EndHorizontal();
            GUILayout.EndArea();

            InPoint.Draw();
            OutPoint.Draw();

            base.Draw();
        }
        private void OnGUI()
        {
            //import cg list
            if (RefreshCGList)
            {
                //refresh list
                CGCount = 0;
                CGList  = new List <CGItem>();

                //find all cg names
                var list = ObjectInfoHelper.GetCGsName();
                foreach (var name in list)
                {
                    CGCount += 1;
                    //get cg sprite
                    string path   = ValueManager.CGPath + name + ".jpg";
                    var    sprite = AssetDatabase.LoadAssetAtPath(path, typeof(Sprite)) as Sprite;
                    CGList.Add(new CGItem {
                        OldName = name, Name = name, CG = sprite
                    });
                }
                RefreshCGList = false;
            }
            //refresh cg list
            if (GUILayout.Button("Refresh CG list"))
            {
                RefreshCGList = true;
            }

            //cg count
            GUILayout.Label("CG count: " + CGCount, GUILayout.Height(15));
            Scroller = GUILayout.BeginScrollView(Scroller);
            for (int i = 0; i < CGCount; i++)
            {
                var myCG = CGList[i];
                GUILayout.BeginHorizontal("box");

                GUILayout.BeginVertical();
                //auto name if string is empty
                if (string.IsNullOrEmpty(myCG.Name))
                {
                    myCG.Name = "cg_" + i;
                }

                myCG.Name = EditorGUILayout.TextField("CG name:", myCG.Name);
                //body sprite
                myCG.CG = EditorGUILayout.ObjectField("CG", myCG.CG, typeof(Sprite), true) as Sprite;
                GUILayout.EndVertical();

                GUILayout.Space(10);
                if (GUILayout.Button("x", GUILayout.Width(20)))
                {
                    CGList.RemoveAt(i);
                    CGCount -= 1;
                }
                GUILayout.EndVertical();
            }
            GUILayout.EndScrollView();

            //add new cg
            GUILayout.BeginHorizontal();
            if (GUILayout.Button("+"))
            {
                CGList.Add(new CGItem());
                CGCount += 1;
            }
            if (GUILayout.Button("-") && CGCount > 0)
            {
                CGCount -= 1;
                CGList.RemoveAt(CGCount);
            }
            GUILayout.EndHorizontal();
            //auto rename cgs
            if (GUILayout.Button("Auto rename"))
            {
                RenameCGs();
            }

            GUILayout.Space(5);
            GUILayout.BeginHorizontal(GUILayout.Height(30));
            GUILayout.Space(5);
            //save cgs
            if (GUILayout.Button("Save", GUILayout.Height(25)))
            {
                SaveCGList();
            }
            //reload cgs
            if (GUILayout.Button("Discard", GUILayout.Height(25)))
            {
                RefreshCGList = true;
            }
            GUILayout.Space(5);
            GUILayout.EndHorizontal();
        }
Ejemplo n.º 3
0
        public override void Draw()
        {
            GUILayout.BeginArea(myRect, Title, Style);
            GUILayout.Space(5);
            GUILayout.BeginHorizontal();
            GUILayout.Space(SpacePixel);
            GUILayout.FlexibleSpace();
            GUILayout.BeginVertical();
            GUILayout.Space(SpacePixel);

            //get all cg
            var list = ObjectInfoHelper.GetCGsName();

            if (Initialize)
            {
                //find origin object
                var origin = AssetDatabase.LoadAssetAtPath(Path, typeof(Sprite)) as Sprite;
                if (origin != null)
                {
                    //set index
                    Index = list.IndexOf(list.Where(c => c == origin.name).FirstOrDefault());
                }
                Initialize = false;
            }

            //selector for cg
            GUILayout.BeginHorizontal();
            GUILayout.Label("CG", WhiteTxtStyle, GUILayout.Width(LabelWidth));
            Index = EditorGUILayout.Popup(Index, list.ToArray());
            GUILayout.EndHorizontal();
            //set cg path
            Path = ValueManager.CGPath + list[Index] + ".jpg";

            //is wait for CG appear
            GUILayout.BeginHorizontal();
            GUILayout.Label("Is wait", WhiteTxtStyle, GUILayout.Width(LabelWidth));
            IsWait = EditorGUILayout.Toggle(IsWait);
            GUILayout.EndHorizontal();

            //GUILayout.BeginHorizontal();
            //GUILayout.FlexibleSpace();
            //load preview cg
            string path       = ValueManager.CGPath + list[Index] + ".jpg";
            var    imgPriveiw = AssetDatabase.LoadAssetAtPath(path, typeof(Sprite)) as Sprite;

            if (imgPriveiw != null)
            {
                GUILayout.Label(imgPriveiw.texture, GUILayout.Width(200), GUILayout.Height(113));
            }
            //GUILayout.EndHorizontal();

            GUILayout.EndVertical();
            GUILayout.Space(SpacePixel);
            GUILayout.EndHorizontal();
            GUILayout.EndArea();

            InPoint.Draw();
            OutPoint.Draw();

            base.Draw();
        }
        void SaveCGList()
        {
            //check if cg list is empty
            if (CGCount <= 0)
            {
                EditorUtility.DisplayDialog("OOOOOps", "No CG Create :(", "OK");
                return;
            }

            for (int i = 0; i < CGCount; i++)
            {
                var CGInfo = CGList[i];
                //create CG
                if (CGInfo.CG != null)
                {
                    //get asset path
                    string directory = AssetDatabase.GetAssetPath(CGInfo.CG);
                    //save path
                    string path = ValueManager.CGPath + CGInfo.Name + ".jpg";

                    //if CG already existe, replace the cg
                    if (AssetDatabase.LoadAssetAtPath(path, typeof(Sprite)) != null)
                    {
                        //replace if cg has changed
                        if (directory != path)
                        {
                            FileUtil.ReplaceFile(directory, path);
                        }
                    }
                    else
                    {
                        //get old cg
                        string oldPath = ValueManager.CGPath + CGInfo.OldName + ".jpg";
                        var    oldCg   = AssetDatabase.LoadAssetAtPath(oldPath, typeof(Sprite)) as Sprite;
                        //change oldCg name if cg already existed
                        if (oldCg != null)
                        {
                            System.IO.File.Move(ValueManager.CGFullPath + CGInfo.OldName + ".jpg", ValueManager.CGFullPath + CGInfo.Name + ".jpg");
                        }
                        else
                        {
                            //save new cg
                            FileUtil.CopyFileOrDirectory(directory, path);
                        }
                    }
                }
            }

            //Delete removed cgs from list
            //get all cgs name
            var existeCGList = ObjectInfoHelper.GetCGsName();
            //delete list
            var deleteCGList = ObjectInfoHelper.GetCGsName();

            foreach (var name in existeCGList)
            {
                //if cg exite in cg manager ,remove it from delete list
                foreach (var cg in CGList)
                {
                    if (name == cg.Name)
                    {
                        deleteCGList.Remove(name);
                    }
                }
            }

            //delete removed cgs
            foreach (var name in deleteCGList)
            {
                string path   = "Assets/GameSources/CGs/" + name + ".jpg";
                var    sprite = AssetDatabase.LoadAssetAtPath(path, typeof(Sprite)) as Sprite;
                if (sprite != null)
                {
                    FileUtil.DeleteFileOrDirectory(path);
                }
            }

            EditorUtility.DisplayDialog("WOAH!!", "CGs saved!!", "OK");
        }
        public override void Draw()
        {
            GUILayout.BeginArea(myRect, Title, Style);
            GUILayout.Space(5);
            GUILayout.BeginHorizontal();
            GUILayout.Space(SpacePixel);
            GUILayout.FlexibleSpace();
            GUILayout.BeginVertical();
            GUILayout.Space(SpacePixel);

            //get all character
            var list = ObjectInfoHelper.GetCharacterNames();

            //set character index if initialize request
            if (Initialize)
            {
                //find origin object
                var origin = AssetDatabase.LoadAssetAtPath(Path, typeof(GameObject)) as GameObject;

                if (origin != null)
                {
                    //set index
                    Index = list.IndexOf(list.Where(c => c == origin.name).FirstOrDefault());
                }
                Initialize = false;
            }

            //choose character
            GUILayout.BeginHorizontal();
            GUILayout.Label("Character", WhiteTxtStyle, GUILayout.Width(LabelWidth));
            Index = EditorGUILayout.Popup(Index, list.ToArray());
            GUILayout.EndHorizontal();

            //find selected character
            string path     = ValueManager.CharaPath + list[Index] + ".prefab";
            var    selected = AssetDatabase.LoadAssetAtPath(path, typeof(GameObject)) as GameObject;

            if (selected != null)
            {
                //set character path
                Path = path;
                //get all sprites name
                var spriteList = selected.GetComponentsInChildren <CharaSpriteSetting>().Select(s => s.name).ToArray();

                //character sprite
                GUILayout.BeginHorizontal();
                GUILayout.Label("Sprite", WhiteTxtStyle, GUILayout.Width(LabelWidth));
                SpriteIndex = EditorGUILayout.Popup(SpriteIndex, spriteList);
                GUILayout.EndHorizontal();

                //select character face if existe
                var faceList = selected.transform.GetChild(SpriteIndex).GetComponentInChildren <CharaFaceSetting>().
                               GetComponentsInChildren <Image>().Select(f => f.name).ToArray();

                if (faceList.Length > 0)
                {
                    //set face index to 0 if has face
                    if (FaceIndex < 0)
                    {
                        FaceIndex = 0;
                    }

                    GUILayout.BeginHorizontal();
                    GUILayout.Label("Face", WhiteTxtStyle, GUILayout.Width(LabelWidth));
                    FaceIndex = EditorGUILayout.Popup(FaceIndex, faceList);
                    GUILayout.EndHorizontal();
                }
                else
                {
                    //no face selected
                    FaceIndex = -1;
                }
            }

            //character postion
            var charaPosList = Enum.GetValues(typeof(CharacterPosition))
                               .Cast <int>()
                               .Select(x => Enum.GetName(typeof(CharacterPosition), x))
                               .ToArray();

            GUILayout.BeginHorizontal();
            GUILayout.Label("Position", WhiteTxtStyle, GUILayout.Width(LabelWidth));
            CharaPos = (CharacterPosition)EditorGUILayout.Popup((int)CharaPos, charaPosList);
            GUILayout.EndHorizontal();

            //custom position
            if (CharaPos == CharacterPosition.Custom)
            {
                if (myRect.height == DefaultRectHeight)
                {
                    myRect.height = DefaultRectHeight + 20;
                }
                CustomPos = EditorGUILayout.Vector2Field("", CustomPos);
            }
            else
            {
                if (myRect.height != DefaultRectHeight)
                {
                    myRect.height = DefaultRectHeight;
                }
            }

            //is wait for character appear
            GUILayout.BeginHorizontal();
            GUILayout.Label("Is wait", WhiteTxtStyle, GUILayout.Width(LabelWidth));
            IsWait = EditorGUILayout.Toggle(IsWait);
            GUILayout.EndHorizontal();

            GUILayout.EndVertical();
            GUILayout.Space(SpacePixel);
            GUILayout.EndHorizontal();
            GUILayout.EndArea();

            InPoint.Draw();
            OutPoint.Draw();

            base.Draw();
        }