Пример #1
0
 public void PrepareConfig(string config)
 {
     config = config.ToLower();
     string[] settings = config.Split('|');
     currentCharacter     = settings[0];
     currentConfiguration = new Dictionary <string, CharacterElement>();
     for (int i = 1; i < settings.Length;)
     {
         string           categoryName = settings[i++];
         string           elementName  = settings[i++];
         CharacterElement element      = null;
         foreach (CharacterElement e in sortedElements[currentCharacter][categoryName])
         {
             if (e.name != elementName)
             {
                 continue;
             }
             element = e;
             break;
         }
         if (element == null)
         {
             throw new System.Exception("未找到Element: " + elementName);
         }
         currentConfiguration.Add(categoryName, element);
     }
     UpdateAssetbundlesAlreadyDownloaded();
 }
Пример #2
0
    public void ChangeElement(string category, bool next)
    {
        List <CharacterElement> availableElements = sortedElements[currentCharacter][category];
        CharacterElement        element           = null;
        int count = availableElements.Count;

        for (int i = 0; i < count; i++)
        {
            if (availableElements[i] != currentConfiguration[category])
            {
                continue;
            }
            if (next)
            {
                element = availableElements[(i + 1) % count];
            }
            else
            {
                element = availableElements[(i - 1) % count];
            }
            break;
        }
        currentConfiguration[category] = element;
        UpdateAssetBundlesAlreadyDownloaded();
    }
        private CharacterElement CreateCharacterGUI(VisualElement root, CharacterAsset asset, CharacterRow character)
        {
            var contentElems  = new List <ContentElement>();
            var characterElem = new CharacterElement {
                userData = contentElems,
                text     = character.Id.Or("<none>")
            };

            var languages      = new List <string>(asset.Languages);
            var languagesPopup = new LanguagePopup("Language Id", languages, 0);

            languagesPopup.RegisterValueChangedCallback(OnChangeLanguage);
            characterElem.Content.Add(languagesPopup);

            CreateAvatarGUI(characterElem.Content, character);
            CreateP1GUI(characterElem.Content, character);
            CreateP1BackgroundGUI(characterElem.Content, character);
            CreateP2GUI(characterElem.Content, character);
            CreateP2BackgroundGUI(characterElem.Content, character);
            CreateP3GUI(characterElem.Content, character);
            CreateP3BackgroundGUI(characterElem.Content, character);
            CreateContentGUI(characterElem.Content, asset, character, contentElems, languages[0]);

            root.Add(characterElem);
            return(characterElem);
        }
Пример #4
0
 /// <summary>
 ///     Destroy data and gamobjects from a character
 /// </summary>
 /// <param name="h">CharacterElement data</param>
 public void DestroyCharacter(CharacterElement h)
 {
     m_characters.Remove(h);
     Destroy(h.associated2DObject);
     Destroy(h.associated3DObject);
     h = null;
 }
Пример #5
0
        public void PrepareConfig(string config)
        {
            config = config.ToLower();
            string[] settings = config.Split('|');
            curRole          = settings[0];
            curConfiguration = new Dictionary <string, CharacterElement>();
            for (int i = 1; i < settings.Length;)
            {
                string           categoryName = settings[i++];
                string           elementName  = settings[i++];
                CharacterElement element      = null;

                if (ConfigManager.GetInstance().DebugMode)
                {
                    foreach (CharacterElement e in sortedElements[curRole][categoryName])
                    {
                        if (e.name != elementName)
                        {
                            continue;
                        }
                        element = e;
                        break;
                    }
                }
                else
                {
                    try
                    {
                        foreach (CharacterElement e in sortedElements[curRole][categoryName])
                        {
                            if (e.name != elementName)
                            {
                                continue;
                            }
                            element = e;
                            break;
                        }
                    }
                    catch (Exception ex)
                    {
                        foreach (string c in sortedElements.Keys)
                        {
                            Debug.LogWarning(c);
                            foreach (string c1 in sortedElements[c].Keys)
                            {
                                Debug.LogWarning("\t" + c1);
                            }
                        }
                        Debug.LogError("item is not exists, categoryName=" + categoryName + ", elementName=" + elementName);
                    }
                }

                if (element == null)
                {
                    Debug.Log("Element not found: " + elementName);
                    continue;
                }
                curConfiguration.Add(categoryName, element);
            }
        }
Пример #6
0
        // draw = false to get the width of the line to be drawn without actually drawing anything. Useful for aligning text.
        private unsafe void RenderTextureLine(List <AElement> atoms, uint *rPtr, ref int x, int y, int linewidth, int maxHeight, ref int lineheight, bool draw)
        {
            for (int i = 0; i < atoms.Count; i++)
            {
                IFont font = atoms[i].Style.Font;
                if (lineheight < font.Height)
                {
                    lineheight = font.Height;
                }
                if (lineheight < atoms[i].Height)
                {
                    lineheight = atoms[i].Height;
                }

                if (draw)
                {
                    if (atoms[i] is CharacterElement)
                    {
                        CharacterElement atom      = (CharacterElement)atoms[i];
                        ICharacter       character = font.GetCharacter(atom.Character);
                        // HREF links should be colored white, because we will hue them at runtime.
                        uint color = atom.Style.IsHREF ? 0xFFFFFFFF : Utility.UintFromColor(atom.Style.Color);
                        character.WriteToBuffer(rPtr, x, y, linewidth, maxHeight, font.Baseline,
                                                atom.Style.IsBold, atom.Style.IsItalic, atom.Style.IsUnderlined, atom.Style.MustDrawnOutline, color, 0xFF000008);
                    }
                    else if (atoms[i] is ImageElement)
                    {
                        ImageElement atom = (atoms[i] as ImageElement);
                        atom.AssociatedImage.Area = new Rectangle(x, y + ((lineheight - atom.Height) / 2), atom.Width, atom.Height);
                    }
                }
                x += atoms[i].Width;
            }
        }
Пример #7
0
        public CharacterImpl(int x, int y, int teamId)
        {
            _team = teamId;

            _gameObject = Object.Instantiate(StaticResources.S.Resources.Character, new Vector3(x, 1f, y), Quaternion.identity);

            var ce = new CharacterElement(this);

            MapManager.S.AddToGrid(x, y, ce);
        }
Пример #8
0
        public GameObject Generate(GameObject root)
        {
            float startTime = Time.realtimeSinceStartup;

            List <CombineInstance> combineInstances = new List <CombineInstance>();
            List <Material>        materials        = new List <Material>();
            List <Transform>       bones            = new List <Transform>();

            Transform[] transforms = root.GetComponentsInChildren <Transform>();

            foreach (KeyValuePair <string, CharacterElement> kvp in curConfiguration)
            {
                CharacterElement    element = kvp.Value;
                SkinnedMeshRenderer smr     = element.GetSkinnedMeshRenderer();
                materials.AddRange(smr.materials);
                for (int sub = 0; sub < smr.sharedMesh.subMeshCount; sub++)
                {
                    CombineInstance ci = new CombineInstance();
                    ci.mesh         = smr.sharedMesh;
                    ci.subMeshIndex = sub;
                    //Debug.LogWarning(smr.sharedMesh.bindposes.Length);
                    combineInstances.Add(ci);
                }

                int boneCount = element.GetBoneNames().Length;
                foreach (string bone in element.GetBoneNames())
                {
                    foreach (Transform transform in transforms)
                    {
                        if (transform.name != bone)
                        {
                            continue;
                        }
                        bones.Add(transform);
                        break;
                    }
                }
                Object.Destroy(smr.gameObject);
            }

            SkinnedMeshRenderer r = root.GetComponent <SkinnedMeshRenderer>();

            r.sharedMesh = new Mesh();
            r.sharedMesh.CombineMeshes(combineInstances.ToArray(), false, false);
            r.bones = bones.ToArray();

            int bones_count     = r.bones.Length;
            int bindposes_count = r.sharedMesh.bindposes.Length;

            //Debug.LogWarning("bones.Count = "+bones_count + " bindposes.Count = "+ bindposes_count + " totalCount ="+totalCount );

            r.materials = materials.ToArray();
            Debug.Log("Generating character took: " + (Time.realtimeSinceStartup - startTime) * 1000 + " ms");
            return(root);
        }
Пример #9
0
    //CreatePartAssetBundle
    //Example:
    //    bundle: female_face-1.assetbundle
    //        - a: GameObject
    //            name: PartAssetGameObjectName(renderobject),
    //            type: GameObject(as Prefab)
    //        - a: Materials
    //            name: material name
    //            type: material
    //        - a: Bones
    //            name: PartAssetBonesName(bonesname)
    //            type: StringHolder
    static void CreatePartAssetBundles(GameObject fbx, string name)
    {
        List <Material> materials = EditorHelpers.CollectAll <Material>(MeterialsPath(fbx));

        foreach (var skinnedMeshRender in fbx.GetComponentsInChildren <SkinnedMeshRenderer>(true))          // get all children with SkinnedMeshRender, even they are disabled
        {
            List <Object> assets = new List <Object>();

            //Prefab for children with skinnedMeshRender
            GameObject rendererClone = (GameObject)PrefabUtility.InstantiatePrefab(skinnedMeshRender.gameObject);
            //delete cloned parent object by side effect
            GameObject rendererCloneParent = rendererClone.transform.parent.gameObject;
            rendererClone.transform.parent = null;
            Object.DestroyImmediate(rendererCloneParent);

            //create prefab for GameObject
            Object rendererPrefab = CreatePrefab(rendererClone, CharacterElement.PartAssetGameObjectName);
            Object.DestroyImmediate(rendererClone);

            assets.Add(rendererPrefab);

            //Materials
            foreach (var material in materials)
            {
                if (material.name.Contains(skinnedMeshRender.name.ToLower()))
                {
                    assets.Add(material);
                }
            }

            //Bones
            List <string> boneNames = new List <string>();
            foreach (var transform in skinnedMeshRender.bones)              //???
            {
                boneNames.Add(transform.name);
            }
            string       boneNameAssetPath = AssetPath + CharacterElement.AssetFileName(CharacterElement.PartAssetBonenames);
            StringHolder holder            = ScriptableObject.CreateInstance <StringHolder>();
            holder.content = boneNames.ToArray();
            AssetDatabase.CreateAsset(holder, boneNameAssetPath);

            // Create bone asset
            Object boneAsset = AssetDatabase.LoadAssetAtPath(boneNameAssetPath, typeof(StringHolder));
            assets.Add(boneAsset);

            //Create bundl by assets
            string bundlePath = AssetBundlePath + name + "_" + skinnedMeshRender.name.ToLower() + ".assetbundle";
            BuildPipeline.BuildAssetBundle(null, assets.ToArray(), bundlePath);

            //Cleanup
            AssetDatabase.DeleteAsset(AssetDatabase.GetAssetPath(rendererPrefab));
            AssetDatabase.DeleteAsset(boneNameAssetPath);
        }
    }
Пример #10
0
        private IEnumerable <CharacterElement> GetAllCharacterElementsOfInputString(string inputArrayElements)
        {
            var listOfCharacterElements = new List <CharacterElement>();

            for (var i = 0; i < inputArrayElements.Length; i++)
            {
                var characterElement = new CharacterElement(inputArrayElements[i].ToString(), GetTypeOfSign(inputArrayElements[i].ToString()));
                listOfCharacterElements.Add(characterElement);
            }
            return(listOfCharacterElements);
        }
Пример #11
0
        /// <summary>
        ///     Create new character and add it to scene
        /// </summary>
        public void CreateNewCharacter()
        {
            var charac = new CharacterElement
            {
                Type       = CharacterType.StandUp,
                SpreadArms = true,
                Size       = new Vector3(1.76f, 1.77f, 0.32f)
            };

            m_characters.Add(charac);
            charac.RebuildSceneData();
            SelectedObjectManager.Instance.Select(charac);
            OperationsBufferScript.Instance.AddAutoSave("Création personnage");
        }
Пример #12
0
    private void makeTAXE()
    {
        //光腿//
        string              partModelName    = "taxe001";
        CharacterElement    partModelElement = sortedElements[currentCharacter][partModelName];
        GameObject          go  = (GameObject)partModelElement.GetWWWBundle().assetBundle.LoadAsset("rendererobject", typeof(GameObject));
        SkinnedMeshRenderer smr = (SkinnedMeshRenderer)go.GetComponent <Renderer>();

        smr.updateWhenOffscreen = true;

        StringHolder stringHolder = (StringHolder)partModelElement.GetWWWBundle().assetBundle.LoadAsset("bonenames", typeof(StringHolder));

        List <Transform> bones = new List <Transform>();

        bones.Clear();
        foreach (string boneName in stringHolder.content)
        {
            foreach (Transform hip in hips)
            {
                if (hip.name != boneName)
                {
                    continue;
                }
                bones.Add(hip);
                break;
            }
        }

        // 更新指定部位 GameObject 的 SkinnedMeshRenderer 内容//
        targetSmr["TAXE"].sharedMesh = smr.sharedMesh;
        targetSmr["TAXE"].quality    = SkinQuality.Bone4;
        targetSmr["TAXE"].bones      = bones.ToArray();
        targetSmr["TAXE"].materials  = smr.materials;

        if (mSockTextureName != "")
        {
            ChangePartTexture(8, mSockTextureName);
        }

        for (int i = 0; i < targetSmr["TAXE"].materials.Length; i++)
        {
            string testShadername = targetSmr["TAXE"].materials[i].shader.name;
            targetSmr["TAXE"].materials[i].shader = Shader.Find(testShadername);
        }
    }
Пример #13
0
 public override bool Equals(object obj)
 {
     if (obj is CharacterElement)
     {
         CharacterElement ce = obj as CharacterElement;
         if (ce.elementsName.Length != elementsName.Length)
         {
             return(false);
         }
         for (int i = 0; i < elementsName.Length; ++i)
         {
             if (!ce.elementsName[i].Equals(elementsName[i]))
             {
                 return(false);
             }
         }
         return(true);
     }
     return(false);
 }
Пример #14
0
    public IEnumerator ChangePart(string part, string item, int partID, bool changePart, string outTexture1 = "", string outTexture2 = "")
    {
        if (partID == 6 || partID == 7 || partID == 8)
        {
            string textureName = part + item;
            StartCoroutine(ChangePartTexture(partID, textureName));
            switch (partID)
            {
            case 6:

                break;

            case 7:
                makeTAXE();
                break;

            case 8:
                break;
            }
        }
        else
        {
            string partModelName = part + item;
            if (partModelName != "" && partModelName != "0")
            {
                partModelName = partModelName.ToLower();
                CharacterElement partModelElement = sortedElements[currentCharacter][partModelName];
                yield return(partModelElement.CreateWWWBundle(AssetbundleBaseURL, GameDefines.AssetBundleVersion));

                GameObject          go  = (GameObject)partModelElement.GetWWWBundle().assetBundle.LoadAsset("rendererobject", typeof(GameObject));
                SkinnedMeshRenderer smr = (SkinnedMeshRenderer)go.GetComponent <Renderer>();
                smr.updateWhenOffscreen = true;

                StringHolder stringHolder = (StringHolder)partModelElement.GetWWWBundle().assetBundle.LoadAsset("bonenames", typeof(StringHolder));
                ChangePartSynchronous(smr, part, item, partID, changePart, stringHolder.content, outTexture1, outTexture2);

                //GameObject.DestroyObject(go);
            }
        }
    }
Пример #15
0
        public void ChangeElement(string catagory, bool next)
        {
            List <CharacterElement> available = sortedElements[curRole][catagory];
            CharacterElement        element   = null;

            for (int i = 0; i < available.Count; i++)
            {
                if (available[i] != curConfiguration[catagory])
                {
                    continue;
                }
                if (next)
                {
                    element = i < available.Count - 1 ? available[i + 1] : available[0];
                }
                else
                {
                    element = i > 0 ? available[i - 1] : available[available.Count - 1];
                }
                break;
            }
            curConfiguration[catagory] = element;
        }
Пример #16
0
    //create map material name -> bundle
    //example: female_face-1 --> female_face-1.assetbundle
    static void CreateElementDataBaseBundle()
    {
        List <CharacterElement> characterElements = new List <CharacterElement>();

        string[] assetBundles = Directory.GetFiles(AssetBundlePath);
        string[] materials    = Directory.GetFiles("Assets/CharacterCustomization/characters", "*.mat", SearchOption.AllDirectories);       //search materials recursively
        foreach (var material in materials)
        {
            foreach (var bundle in assetBundles)
            {
                FileInfo bundleFI   = new FileInfo(bundle);
                FileInfo materialFI = new FileInfo(material);
                string   bundleName = bundleFI.Name.Replace(CharacterElement.BundlePostfix, "");

                if (!materialFI.Name.StartsWith(bundleName) ||
                    !material.Contains("Per Texture Materials"))
                {
                    continue;
                }

                string name = materialFI.Name.Replace(".mat", "");
                characterElements.Add(new CharacterElement(name, bundleName));
                break;
            }
        }

        CharacterElementHolder holder = ScriptableObject.CreateInstance <CharacterElementHolder>();

        holder.content = characterElements;
        string path = AssetPath + CharacterElement.AssetFileName(CharacterElement.DataBaseName);

        AssetDatabase.CreateAsset(holder, path);
        Object asset = AssetDatabase.LoadAssetAtPath(path, typeof(CharacterElementHolder));

        BuildPipeline.BuildAssetBundle(asset, null, AssetBundlePath + CharacterElement.BundleFileName(CharacterElement.DataBaseName));
    }
Пример #17
0
    public void ChangeElement(string catagory, bool next)
    {
        List <CharacterElement> available = sortedElements[currentCharacter][catagory];
        CharacterElement        element   = null;

        for (int i = 0; i < available.Count; i++)
        {
            if (available[i] != currentConfiguration[catagory])
            {
                continue;
            }
            if (next)
            {
                element = i < available.Count - 1 ? available[i + 1] : available[0];
            }
            else
            {
                element = i > 0 ? available[i - 1] : available[available.Count - 1];
            }
            break;
        }
        currentConfiguration[catagory] = element;
        UpdateAssetbundlesAlreadyDownloaded();
    }
Пример #18
0
        /// <summary>
        /// Gets a single word of AElements to lay out.
        /// </summary>
        /// <param name="elements">The list of elements to get the word from.</param>
        /// <param name="start">The index in the elements list to start getting the word.</param>
        /// <param name="wordWidth">The width of the word of elements.</param>
        /// <param name="styleWidth">Italic and Outlined characters need more room for the slant/outline (Bold handled differently).</param>
        /// <param name="wordHeight"></param>
        /// <param name="ascender">Additional pixels above the top of the word. Affects dimensions of the parent if word is on the first line.</param>
        /// <returns></returns>
        List <AElement> LayoutElementsGetWord(List <AElement> elements, int start, out int wordWidth, out int styleWidth, out int wordHeight, out int ascender)
        {
            List <AElement> word = new List <AElement>();

            wordWidth  = 0;
            wordHeight = 0;
            styleWidth = 0;
            ascender   = 0;
            for (int i = start; i < elements.Count; i++)
            {
                if (elements[i].IsThisAtomALineBreak)
                {
                    return(word);
                }
                if (elements[i].CanBreakAtThisAtom)
                {
                    if (word.Count > 0)
                    {
                        return(word);
                    }
                }
                word.Add(elements[i]);
                wordWidth  += elements[i].Width;
                styleWidth -= elements[i].Width;
                if (styleWidth < 0)
                {
                    styleWidth = 0;
                }
                if (wordHeight < elements[i].Height)
                {
                    wordHeight = elements[i].Height;
                }
                // we may need to add additional width for special style characters.
                if (elements[i] is CharacterElement)
                {
                    CharacterElement atom = (CharacterElement)elements[i];
                    IFont            font = atom.Style.Font;
                    ICharacter       ch   = font.GetCharacter(atom.Character);
                    // italic characters need a little extra width if they are at the end of the line.
                    if (atom.Style.IsItalic)
                    {
                        styleWidth = font.Height / 2;
                    }
                    if (atom.Style.DrawOutline)
                    {
                        styleWidth += 2;
                        if (-1 < ascender)
                        {
                            ascender = -1;
                        }
                    }
                    if (ch.YOffset + ch.Height > wordHeight)
                    {
                        wordHeight = ch.YOffset + ch.Height;
                    }
                    if (ch.YOffset < 0 && ascender > ch.YOffset)
                    {
                        ascender = ch.YOffset;
                    }
                }
                if (i == elements.Count - 1 || elements[i].CanBreakAtThisAtom)
                {
                    return(word);
                }
            }
            return(word);
        }
Пример #19
0
        // ============================================================================================================
        // Parse and create boxes
        // ============================================================================================================

        BlockElement ParseHtmlToBlocks(string html)
        {
            IResourceProvider provider = Service.Get <IResourceProvider>();
            StyleParser       styles = new StyleParser(provider);
            BlockElement      root, currentBlock;

            root = currentBlock = new BlockElement("root", styles.Style); // this is the root!
            // if this is not HTML, do not parse tags. Otherwise search out and interpret tags.
            bool parseHTML = true;

            if (!parseHTML)
            {
                for (int i = 0; i < html.Length; i++)
                {
                    currentBlock.AddAtom(new CharacterElement(styles.Style, html[i]));
                }
            }
            else
            {
                m_Parser.Init(html);
                HTMLchunk chunk;
                while ((chunk = ParseNext(m_Parser)) != null)
                {
                    if (!(chunk.oHTML == string.Empty))
                    {
                        // This is a span of text.
                        string text = chunk.oHTML;
                        // make sure to replace escape characters!
                        text = EscapeCharacters.ReplaceEscapeCharacters(text);
                        //Add the characters to the current box
                        for (int i = 0; i < text.Length; i++)
                        {
                            currentBlock.AddAtom(new CharacterElement(styles.Style, text[i]));
                        }
                    }
                    else
                    {
                        // This is a tag. interpret the tag and edit the openTags list.
                        // It may also be an atom, in which case we should add it to the list of atoms!
                        AElement atom = null;
                        if (chunk.bClosure && !chunk.bEndClosure)
                        {
                            styles.CloseOneTag(chunk);
                            if (currentBlock.Tag == chunk.sTag)
                            {
                                currentBlock = currentBlock.Parent;
                            }
                        }
                        else
                        {
                            bool isBlockTag = false;
                            switch (chunk.sTag)
                            {
                            // ====================================================================================
                            // Anchor elements are added to the open tag collection as HREFs.
                            case "a":
                                styles.InterpretHREF(chunk, null);
                                break;

                            // ====================================================================================
                            // These html elements are ignored.
                            case "body":
                                break;

                            // ====================================================================================
                            // These html elements are blocks but can also have styles
                            case "center":
                            case "left":
                            case "right":
                            case "div":
                                atom = new BlockElement(chunk.sTag, styles.Style);
                                styles.ParseTag(chunk, atom);
                                isBlockTag = true;
                                break;

                            // ====================================================================================
                            // These html elements are styles, and are added to the StyleParser.
                            case "span":
                            case "font":
                            case "b":
                            case "i":
                            case "u":
                            case "outline":
                            case "big":
                            case "basefont":
                            case "medium":
                            case "small":
                                styles.ParseTag(chunk, null);
                                break;

                            // ====================================================================================
                            // These html elements are added as atoms only. They cannot impart style
                            // onto other atoms.
                            case "br":
                                atom = new CharacterElement(styles.Style, '\n');
                                break;

                            case "gumpimg":
                                // draw a gump image
                                atom = new ImageElement(styles.Style, ImageElement.ImageTypes.UI);
                                styles.ParseTag(chunk, atom);
                                break;

                            case "itemimg":
                                // draw a static image
                                atom = new ImageElement(styles.Style, ImageElement.ImageTypes.Item);
                                styles.ParseTag(chunk, atom);
                                break;

                            // ====================================================================================
                            // Every other element is not interpreted, but rendered as text. Easy!
                            default:
                            {
                                string text = html.Substring(chunk.iChunkOffset, chunk.iChunkLength);
                                // make sure to replace escape characters!
                                text = EscapeCharacters.ReplaceEscapeCharacters(text);
                                //Add the characters to the current box
                                for (int i = 0; i < text.Length; i++)
                                {
                                    currentBlock.AddAtom(new CharacterElement(styles.Style, text[i]));
                                }
                            }
                            break;
                            }

                            if (atom != null)
                            {
                                currentBlock.AddAtom(atom);
                                if (isBlockTag && !chunk.bEndClosure)
                                {
                                    currentBlock = (BlockElement)atom;
                                }
                            }
                            styles.CloseAnySoloTags();
                        }
                    }
                }
            }

            return(root);
        }
Пример #20
0
        private string ParsingCurrentCharacterElement(CharacterElement item,
                                                      Stack <CharacterElement> stack, ref bool isPreviousCharIsLetter)
        {
            var resultingReversePolishSignature = String.Empty;
            var termnalSign = String.Empty;

            if (item.TypeOfSign == TypeOfSign.Letter)
            {
                if (!isPreviousCharIsLetter)
                {
                    termnalSign            = "$";
                    isPreviousCharIsLetter = true;
                }

                resultingReversePolishSignature += termnalSign + item.CharValue;
            }
            else
            {
                if (isPreviousCharIsLetter)
                {
                    resultingReversePolishSignature += "$";
                }

                isPreviousCharIsLetter = false;

                if (stack.Count == 0)
                {
                    stack.Push(item);
                }
                else if (item.CharValue == ")")
                {
                    while (true)
                    {
                        if (stack.Peek().CharValue == "(")
                        {
                            stack.Pop();
                            break;
                        }
                        if (PeekOfStackIsBracket(stack))
                        {
                            resultingReversePolishSignature += stack.Peek().CharValue;
                        }

                        stack.Pop();
                    }
                }
                else if (item.TypeOfSign == TypeOfSign.OpeningBracket || (item.TypeOfSign > stack.Peek().TypeOfSign))
                {
                    stack.Push(item);
                }
                else if (item.TypeOfSign <= stack.Peek().TypeOfSign)
                {
                    while (item.TypeOfSign <= stack.Peek().TypeOfSign)
                    {
                        resultingReversePolishSignature += stack.Pop().CharValue;
                    }
                    stack.Push(item);
                }
            }
            return(resultingReversePolishSignature);
        }
    public void ChangeElements(IDictionary <string, string> changes)
    {
        if (changes.ContainsKey(CHARACTER_PROP))
        {
            string newCharacter = changes[CHARACTER_PROP];

            if (newCharacter.Equals("next"))
            {
                ChangeCharacter(true);
            }
            else if (newCharacter.Equals("prev"))
            {
                ChangeCharacter(false);
            }
            else if (!availableCharacters.Contains(newCharacter))
            {
                throw new Exception("CharacterGenerator.ChangeElements passed invalid " + CHARACTER_PROP + ": " + newCharacter);
            }

            return;
        }

        foreach (string category in changes.Keys)
        {
            List <CharacterElement> available = sortedElements[currentCharacter][category];
            CharacterElement        element   = null;
            string newElmName = changes[category];

            if (propertyDescriptors[currentCharacter][category].ContainsKey(newElmName))
            {
                newElmName = propertyDescriptors[currentCharacter][category][newElmName];
            }

            bool next = newElmName.Equals("next");

            if (next || newElmName.Equals("prev"))
            {
                for (int i = 0; i < available.Count; i++)
                {
                    if (available[i] != currentConfiguration[category])
                    {
                        continue;
                    }
                    if (next)
                    {
                        element = i < available.Count - 1 ? available[i + 1] : available[0];
                    }
                    else
                    {
                        element = i > 0 ? available[i - 1] : available[available.Count - 1];
                    }
                    break;
                }
            }
            else
            {
                for (int i = 0; i < available.Count; i++)
                {
                    if (available[i].name != newElmName)
                    {
                        continue;
                    }
                    element = available[i];
                    break;
                }
                if (element == null)
                {
                    throw new Exception("CharacterGenerator.ChangeElements: Element for " + category + " not found: " + newElmName);
                }
            }

            currentConfiguration[category] = element;
        }

        //Debug.Log("currentConfiguration after: " + PrintCharacterElementDictionary(currentConfiguration));

        UpdateAssetbundlesAlreadyDownloaded();
    }
 public WrappedElement(IGameObject element, CharacterElement type)
 {
     Element     = element;
     ElementType = type;
 }
Пример #23
0
    // Sets the configuration of a category to the next or previous
    // CharacterElement in sortedElements.
    public bool ChangeElementWithSelectName(string configer)
    {
        string[] settings = configer.Split('_');
        string catagory = settings [1];

        string material = configer;
        string bundle="";
        for(int i=0;i<settings.Length-1;i++){
            bundle = bundle + settings [i] + "_";
        }

        bundle = bundle.Remove (bundle.LastIndexOf("_"));
        bundle += ".assetbundle";

        //		FileInfo bundleFI = new FileInfo(bundle);
        //		FileInfo materialFI = new FileInfo(material);

        CharacterElement element=new CharacterElement(material, bundle);
        if (element.name == currentConfiguration[catagory].name)
            return false;

        currentConfiguration[catagory] = element;
        UpdateAssetbundlesAlreadyDownloaded();
        return true;
    }
Пример #24
0
        // ======================================================================
        // Old code
        // ======================================================================

        private void DoLayoutOld(AElement root, int maxwidth, out int width, out int height, out int ascender)
        {
            // default values for out variables.
            width    = 0;
            height   = 0;
            ascender = 0;

            // local variables
            int  descenderHeight = 0;
            int  lineHeight      = 0;
            int  styleWidth      = 0;        // italic + outlined characters need more room for the slant/outline.
            int  widestLine      = maxwidth; // we automatically set the content to fill the specified width.
            int  wordWidth       = 0;
            bool firstLine       = true;

            List <AElement> word     = new List <AElement>();
            List <AElement> elements = null;

            for (int i = 0; i < elements.Count; i++)
            {
                wordWidth  += elements[i].Width;
                styleWidth -= elements[i].Width;
                if (styleWidth < 0)
                {
                    styleWidth = 0;
                }

                if (lineHeight < elements[i].Height)
                {
                    lineHeight = elements[i].Height;
                }

                if (elements[i].IsThisAtomALineBreak)
                {
                    if (width + styleWidth > widestLine)
                    {
                        widestLine = width + styleWidth;
                    }
                    height         += lineHeight;
                    descenderHeight = 0;
                    lineHeight      = 0;
                    width           = 0;
                    firstLine       = false;
                }
                else
                {
                    word.Add(elements[i]);

                    // we may need to add additional width for special style characters.
                    if (elements[i] is CharacterElement)
                    {
                        CharacterElement atom = (CharacterElement)elements[i];
                        IFont            font = atom.Style.Font;
                        ICharacter       ch   = font.GetCharacter(atom.Character);

                        // italic characters need a little extra width if they are at the end of the line.
                        if (atom.Style.IsItalic)
                        {
                            styleWidth = font.Height / 2;
                        }
                        if (atom.Style.MustDrawnOutline)
                        {
                            styleWidth += 2;
                        }
                        if (ch.YOffset + ch.Height - lineHeight > descenderHeight)
                        {
                            descenderHeight = ch.YOffset + ch.Height - lineHeight;
                        }
                        if (ch.YOffset < 0 && firstLine && ascender > ch.YOffset)
                        {
                            ascender = ch.YOffset;
                        }
                    }

                    if (i == elements.Count - 1 || elements[i + 1].CanBreakAtThisAtom)
                    {
                        // Now make sure this line can fit the word.
                        if (width + wordWidth + styleWidth <= maxwidth)
                        {
                            // it can fit!
                            width    += wordWidth + styleWidth;
                            wordWidth = 0;
                            word.Clear();
                            // if this word is followed by a space, does it fit? If not, drop it entirely and insert \n after the word.
                            if (!(i == elements.Count - 1) && elements[i + 1].IsThisAtomABreakingSpace)
                            {
                                int charwidth = elements[i + 1].Width;
                                if (width + charwidth <= maxwidth)
                                {
                                    // we can fit an extra space here.
                                    width += charwidth;
                                    i++;
                                }
                                else
                                {
                                    // can't fit an extra space on the end of the line. replace the space with a \n.
                                    ((CharacterElement)elements[i + 1]).Character = '\n';
                                }
                            }
                        }
                        else
                        {
                            // this word cannot fit in the current line.
                            if ((width > 0) && (i - word.Count >= 0))
                            {
                                // if this is the last word in a line. Replace the last space character with a line break
                                // and back up to the beginning of this word.
                                if (elements[i - word.Count].IsThisAtomABreakingSpace)
                                {
                                    ((CharacterElement)elements[i - word.Count]).Character = '\n';
                                    i = i - word.Count - 1;
                                }
                                else
                                {
                                    StyleState inheritedStyle = elements[i - word.Count].Style;
                                    elements.Insert(i - word.Count, new CharacterElement(inheritedStyle, '\n'));
                                    i = i - word.Count;
                                }
                                word.Clear();
                                wordWidth = 0;
                            }
                            else
                            {
                                // this is the only word on the line and we will need to split it.
                                // first back up until we've reached the reduced the size of the word
                                // so that it fits on one line, and split it there.
                                int iWordWidth = wordWidth;
                                for (int j = word.Count - 1; j >= 1; j--)
                                {
                                    int iDashWidth = word[j].Style.Font.GetCharacter('-').Width;
                                    if (iWordWidth + iDashWidth <= maxwidth)
                                    {
                                        StyleState inheritedStyle = elements[i - (word.Count - j) + 1].Style;
                                        elements.Insert(i - (word.Count - j) + 1, new CharacterElement(inheritedStyle, '\n'));
                                        elements.Insert(i - (word.Count - j) + 1, new CharacterElement(inheritedStyle, '-'));
                                        break;
                                    }
                                    iWordWidth -= word[j].Width;
                                }
                                i -= word.Count + 2;
                                word.Clear();
                                width     = 0;
                                wordWidth = 0;
                                if (i < 0)
                                {
                                    // the texture size is too small to hold this small number of characters. This is a problem.
                                    i = -1;
                                    return;
                                }
                            }
                        }
                    }
                }
            }

            width  += styleWidth;
            height += lineHeight + descenderHeight;
            if (widestLine > width)
            {
                width = widestLine;
            }
        }
Пример #25
0
    public IEnumerator  generateCharacterFromConfigSynchronous(int characterId, string animationName)
    {
        currentCharacter = "a001";

        if (!characterBaseWWWs.ContainsKey(currentCharacter))
        {
            var www = WWW.LoadFromCacheOrDownload(AssetbundleBaseURL + currentCharacter + "_characterbase.assetbundle", GameDefines.AssetBundleVersion);
            characterBaseWWWs.Add(currentCharacter, www);
            yield return(characterBaseWWWs[currentCharacter]);
        }


        if (!characterBaseRequests.ContainsKey(currentCharacter))
        {
            //AssetBundleRequest requestCBase = ;
            characterBaseRequests.Add(currentCharacter, CurrentCharacterBase.assetBundle.LoadAssetAsync("characterbase", typeof(GameObject)));
            //if (!characterBaseRequests[currentCharacter].isDone)
            //	return false;
            yield return(characterBaseRequests[currentCharacter]);
        }


        if (hips == null || hips.Length == 0)
        {
            GameObject root = (GameObject)Object.Instantiate(characterBaseRequests[currentCharacter].asset);
            animator              = root.GetComponent <Animator>();
            root.name             = currentCharacter;
            root.transform.parent = target;

            for (int i = 0; i < PartListLength; i++)
            {
                GameObject partObj = new GameObject();
                partObj.name             = InnerPartList[i];
                partObj.transform.parent = root.transform;
                //为新建立的 GameObject 加入 SkinnedMeshRenderer,并将此 SkinnedMeshRenderer 存入 targetSmr
                targetSmr.Add(InnerPartList[i], partObj.AddComponent <SkinnedMeshRenderer>());
            }

            //从目标物件取得骨架资料 (Female_Hips 的全部物件)
            hips = root.GetComponentsInChildren <Transform>();

            root.transform.localPosition = Vector3.zero;
        }

        if (mCharacterConfig == null)
        {
            mCharacterConfig = Globals.Instance.MDataTableManager.GetConfig <CharacterConfig>();
        }

        mCharacterConfig.GetCharacterObject(characterId, out mCharacterObj);

        if (mItemConfig == null)
        {
            mItemConfig = Globals.Instance.MDataTableManager.GetConfig <ItemConfig>();
        }
        ItemConfig.ItemElement element = null;

        for (int i = 0; i < 19; i++)
        {
            ///内衣内裤袜子///
            if (i == 5 || i == 6 || i == 7)
            {
                continue;
            }
            string partModelName = mCharacterObj.PartInfoList[i].partModelName;
            if (partModelName != "" && partModelName != "0")
            {
                partModelName = partModelName.ToLower();
                CharacterElement partModelElement = sortedElements[currentCharacter][partModelName];

                //if(!partModelElement.WWWBundle.isDone)
                //return false;
                yield return(partModelElement.CreateWWWBundle(AssetbundleBaseURL, GameDefines.AssetBundleVersion));
            }
        }

        ///20-25 肉体 ////
        for (int i = 13; i < 19; i++)
        {
            string partModelName = mCharacterObj.PartInfoList[i].partModelName;
            if (partModelName != "" && partModelName != "0")
            {
                string partName  = partModelName.Substring(0, partModelName.Length - 3);
                string partIDStr = partModelName.Substring(partModelName.Length - 3, 3);
                partModelName = partModelName.ToLower();
                CharacterElement partModelElement = sortedElements[currentCharacter][partModelName];


                GameObject          go  = (GameObject)partModelElement.GetWWWBundle().assetBundle.LoadAsset("rendererobject", typeof(GameObject));
                SkinnedMeshRenderer smr = (SkinnedMeshRenderer)go.GetComponent <Renderer>();
                smr.updateWhenOffscreen = true;

                StringHolder stringHolder = (StringHolder)partModelElement.GetWWWBundle().assetBundle.LoadAsset("bonenames", typeof(StringHolder));

                ChangePartSynchronous(smr, partName, partIDStr, mCharacterObj.PartInfoList[i].partID, false, stringHolder.content);
            }
        }
        ///1-13 头发和衣服//
        for (int i = 0; i < 13; i++)
        {
            string partModelName = mCharacterObj.PartInfoList[i].partModelName;
            ///内衣内裤袜子///
            if (i == 5 || i == 6 || i == 7)
            {
                continue;
            }
            if (partModelName != "" && partModelName != "0")
            {
                string partName  = partModelName.Substring(0, partModelName.Length - 3);
                string partIDStr = partModelName.Substring(partModelName.Length - 3, 3);

                bool   IsHas           = mItemConfig.GetItemElement(mCharacterObj.PartInfoList[i].ItemID, out element);
                string outTextureName0 = "";
                string outTextureName1 = "";
                if (IsHas)
                {
                    outTextureName0 = element.OutTextureName0;
                    outTextureName1 = element.OutTextureName1;
                }
                partModelName = partModelName.ToLower();
                CharacterElement partModelElement = sortedElements[currentCharacter][partModelName];


                GameObject          go  = (GameObject)partModelElement.GetWWWBundle().assetBundle.LoadAsset("rendererobject", typeof(GameObject));
                SkinnedMeshRenderer smr = (SkinnedMeshRenderer)go.GetComponent <Renderer>();
                smr.updateWhenOffscreen = true;

                StringHolder stringHolder = (StringHolder)partModelElement.GetWWWBundle().assetBundle.LoadAsset("bonenames", typeof(StringHolder));

                ChangePartSynchronous(smr, partName, partIDStr, mCharacterObj.PartInfoList[i].partID, false, stringHolder.content, outTextureName0, outTextureName1);
            }
        }

        for (int i = 5; i < 8; i++)
        {
            string partModelName = mCharacterObj.PartInfoList[i].partModelName;
            if (partModelName != "")
            {
                ChangePartTexture(mCharacterObj.PartInfoList[i].partID, partModelName);
            }
        }



        mCharacterConfigId = characterId;

        yield return(true);
    }
Пример #26
0
    public IEnumerator  generageCharacterFormGirlDataSynchronous(GirlData girlData)
    {
        currentCharacter = "a001";

        if (mCharacterConfig == null)
        {
            mCharacterConfig = Globals.Instance.MDataTableManager.GetConfig <CharacterConfig>();
        }
//		mCharacterConfig.GetCharacterObject(girlData.BasicData.LogicID,out mCharacterObj);

        if (!characterBaseWWWs.ContainsKey(currentCharacter))
        {
            var www = WWW.LoadFromCacheOrDownload(AssetbundleBaseURL + currentCharacter + "_characterbase.assetbundle", GameDefines.AssetBundleVersion);
            characterBaseWWWs.Add(currentCharacter, www);
            yield return(characterBaseWWWs[currentCharacter]);
        }


        if (!characterBaseRequests.ContainsKey(currentCharacter))
        {
            //AssetBundleRequest requestCBase = ;
            characterBaseRequests.Add(currentCharacter, CurrentCharacterBase.assetBundle.LoadAssetAsync("characterbase", typeof(GameObject)));
            yield return(characterBaseRequests[currentCharacter]);
        }


        if (hips == null || hips.Length == 0)
        {
            GameObject root = (GameObject)Object.Instantiate(characterBaseRequests[currentCharacter].asset);
            animator              = root.GetComponent <Animator>();
            root.name             = currentCharacter;
            root.transform.parent = target;

            for (int i = 0; i < PartListLength; i++)
            {
                GameObject partObj = new GameObject();
                partObj.name             = InnerPartList[i];
                partObj.transform.parent = root.transform;
                //为新建立的 GameObject 加入 SkinnedMeshRenderer,并将此 SkinnedMeshRenderer 存入 targetSmr
                targetSmr.Add(InnerPartList[i], partObj.AddComponent <SkinnedMeshRenderer>());
            }

            //从目标物件取得骨架资料 (Female_Hips 的全部物件)
            hips = root.GetComponentsInChildren <Transform>();

            root.transform.localPosition    = Vector3.zero;
            root.transform.localEulerAngles = Vector3.zero;
        }


        ///2-13 衣服//
        for (int i = mInedxIter; i < 19; i++)
        {
            Debug.Log("i is : " + mInedxIter.ToString());
            ///内衣内裤袜子///
            if (i == 5 || i == 6 || i == 7)
            {
                string textureName = mCharacterObj.PartInfoList[i].partModelName;
                switch (mCharacterObj.PartInfoList[i].partID)
                {
                case 6:
                    mBaraTextureName = textureName;
                    break;

                case 7:
                    mUnderTextureName = textureName;
                    break;

                case 8:
                    mSockTextureName = textureName;
                    break;
                }
                continue;
            }

            ItemSlotData itemSlotData = null;
            girlData.ClothDatas.TryGetValue(mCharacterObj.PartInfoList[i].partID, out itemSlotData);
            if (itemSlotData != null)
            {
                if (mItemConfig == null)
                {
                    mItemConfig = Globals.Instance.MDataTableManager.GetConfig <ItemConfig> ();
                }

                ItemConfig.ItemElement element = null;
                bool IsHas = mItemConfig.GetItemElement(itemSlotData.MItemData.BasicData.LogicID, out element);
                if (!IsHas)
                {
                    yield return(false);
                }
                string partModelName = element.ModelName;

                if (partModelName != "" && partModelName != "0")
                {
                    partModelName = partModelName.ToLower();
                    CharacterElement partModelElement = sortedElements[currentCharacter][partModelName];
                    yield return(partModelElement.CreateWWWBundle(AssetbundleBaseURL, GameDefines.AssetBundleVersion));
                }
            }
            else
            {
                string partModelName = mCharacterObj.PartInfoList[i].partModelName;
                if (partModelName != "" && partModelName != "0")
                {
                    partModelName = partModelName.ToLower();
                    CharacterElement partModelElement = sortedElements[currentCharacter][partModelName];
                    yield return(partModelElement.CreateWWWBundle(AssetbundleBaseURL, GameDefines.AssetBundleVersion));
                }
            }
        }

        ///20-25 肉体 ////
        for (int i = 13; i < 19; i++)
        {
            string partModelName = mCharacterObj.PartInfoList[i].partModelName;
            if (partModelName != "" && partModelName != "0")
            {
                string partName  = partModelName.Substring(0, partModelName.Length - 3);
                string partIDStr = partModelName.Substring(partModelName.Length - 3, 3);
                partModelName = partModelName.ToLower();
                CharacterElement partModelElement = sortedElements[currentCharacter][partModelName];


                GameObject          go  = (GameObject)partModelElement.GetWWWBundle().assetBundle.LoadAsset("rendererobject", typeof(GameObject));
                SkinnedMeshRenderer smr = (SkinnedMeshRenderer)go.GetComponent <Renderer>();
                smr.updateWhenOffscreen = true;

                StringHolder stringHolder = (StringHolder)partModelElement.GetWWWBundle().assetBundle.LoadAsset("bonenames", typeof(StringHolder));

                ChangePartSynchronous(smr, partName, partIDStr, mCharacterObj.PartInfoList[i].partID, false, stringHolder.content);
            }
        }
        ///1-13 头发和衣服//
        for (int i = 0; i < 13; i++)
        {
            string partModelName = mCharacterObj.PartInfoList[i].partModelName;
            ///内衣内裤袜子///
            if (i == 5 || i == 6 || i == 7)
            {
                continue;
            }
            if (partModelName != "" && partModelName != "0")
            {
                string partName  = partModelName.Substring(0, partModelName.Length - 3);
                string partIDStr = partModelName.Substring(partModelName.Length - 3, 3);
                ItemConfig.ItemElement element = null;
                bool   IsHas           = mItemConfig.GetItemElement(mCharacterObj.PartInfoList[i].ItemID, out element);
                string outTextureName0 = "";
                string outTextureName1 = "";
                if (IsHas)
                {
                    outTextureName0 = element.OutTextureName0;
                    outTextureName1 = element.OutTextureName1;
                }
                partModelName = partModelName.ToLower();
                CharacterElement partModelElement = sortedElements[currentCharacter][partModelName];


                GameObject          go  = (GameObject)partModelElement.GetWWWBundle().assetBundle.LoadAsset("rendererobject", typeof(GameObject));
                SkinnedMeshRenderer smr = (SkinnedMeshRenderer)go.GetComponent <Renderer>();
                smr.updateWhenOffscreen = true;

                StringHolder stringHolder = (StringHolder)partModelElement.GetWWWBundle().assetBundle.LoadAsset("bonenames", typeof(StringHolder));

                ChangePartSynchronous(smr, partName, partIDStr, mCharacterObj.PartInfoList[i].partID, false, stringHolder.content, outTextureName0, outTextureName1);
            }
        }

        for (int i = 5; i < 8; i++)
        {
            string partModelName = mCharacterObj.PartInfoList[i].partModelName;
            ChangePartTexture(mCharacterObj.PartInfoList[i].partID, partModelName);
        }


        yield break;
    }
Пример #27
0
 //Due to our last lection we can use IEnumerable as Re# suggests (Not critical)
 private List<CharacterElement> GetAllCharacterElementsOfInputString(string inputArrayElements)
 {
     var listOfCharacterElements = new List<CharacterElement>();
     for (var i = 0; i < inputArrayElements.Length; i++)
     {
         var characterElement = new CharacterElement(inputArrayElements[i].ToString(), GetTypeOfSign(inputArrayElements[i].ToString()));
         listOfCharacterElements.Add(characterElement);
     }
     return listOfCharacterElements;
 }
Пример #28
0
        //Bellow we have so many low-quality code from lab made in first year of university. I don't think I can take it anymore.
        //Code bellow has not been inspected due to this reasons
        private string ParsingCurrentCharacterElement(CharacterElement item,
            Stack<CharacterElement> stack, ref bool isPreviousCharIsLetter)
        {
            var resultingReversePolishSignature = String.Empty;
            var termnalSign = String.Empty;

            if (item.TypeOfSign == TypeOfSign.Letter)
            {
                if (!isPreviousCharIsLetter)
                {
                    termnalSign = "$";
                    isPreviousCharIsLetter = true;
                }

                resultingReversePolishSignature += termnalSign + item.CharValue;
            }
            else
            {
                if (isPreviousCharIsLetter)
                {
                    resultingReversePolishSignature += "$";
                }

                isPreviousCharIsLetter = false;

                if (stack.Count == 0)
                {
                    stack.Push(item);
                }
                else if (item.CharValue == ")")
                {
                    while (true)
                    {
                        if (stack.Peek().CharValue == "(")
                        {
                            stack.Pop();
                            break;
                        }
                        if (PeekOfStackIsBracket(stack))
                        {
                            resultingReversePolishSignature += stack.Peek().CharValue;
                        }

                        stack.Pop();
                    }
                }
                else if (item.TypeOfSign == TypeOfSign.OpeningBracket || (item.TypeOfSign > stack.Peek().TypeOfSign))
                {
                    stack.Push(item);
                }
                else if (item.TypeOfSign <= stack.Peek().TypeOfSign)
                {
                    while (item.TypeOfSign <= stack.Peek().TypeOfSign)
                    {
                        resultingReversePolishSignature += stack.Pop().CharValue;
                    }
                    stack.Push(item);
                }
            }
            return resultingReversePolishSignature;
        }