コード例 #1
0
        /// <summary>
        /// Loads A component.
        /// </summary>
        /// <returns>The A component.</returns>
        /// <param name="sr">Sr.</param>
        static IZComponent LoadAComponent(StringReader sr)
        {
            string sl      = "";
            string ret     = "";
            Type   comType = default(Type);

            //read name
            sl      = sr.ReadLine();
            comType = ComponentsRuntimePool <IZComponent> .GetType(sl);

            while (sl != null)
            {
                sl = sr.ReadLine();
                if (sl.CompareTo(ComponentPrefix) == 0)
                {
                    break;
                }

                if (sl != "")
                {
                    ret += sl;
                }
            }
            //sr.Close();

            IZComponent c = ComponentsRuntimePool <IZComponent> .CreateComponent(comType);

            object boxedStruct = c;

            JsonUtility.FromJsonOverwrite(ret, boxedStruct);                    //editor.curPool.Json.text

            c = (IZComponent)boxedStruct;

            return(c);
        }
コード例 #2
0
        //bool bUnfolded = false;
        /// <summary>
        /// Draws the component.
        /// </summary>
        /// <param name="com">COM.</param>
        void DrawComponent(IZComponent com)
        {
            int iconSize = (int)EditorGUIUtility.singleLineHeight;
            //draw component member
            Rect rect        = EditorGUILayout.BeginVertical(entityStyle);
            Type ty          = com.GetType();
            var  memberInfos = ty.GetPublicMemberInfos();

            bool bUnfolded = poolConfig.unfoldMap.IsUnfold(curEntity.Name + ty.Name);

            //SerializedProperty unfoledObj = serializedObject.FindProperty ("unfoldMap");

            //draw component file info
            EditorGUILayout.BeginHorizontal();
            {
                if (memberInfos.Count == 0)
                {
                    EditorGUILayout.LabelField("    " + ty.Name, EditorStyles.boldLabel);
                }
                else
                {
                    bool bNewUnfold = EditorLayout.Foldout(bUnfolded, ty.Name, iconSize + 10);
                    //EditorGUILayout.LabelField(ty.Name, EditorStyles.boldLabel);
                    if (bNewUnfold != bUnfolded)
                    {
                        poolConfig.unfoldMap.SetUnfold(curEntity.Name + ty.Name, bNewUnfold);

//						unfoldObj.Update();
//						unfoldObj.ApplyModifiedProperties ();
                    }
                }
                if (EditorLayout.MiniButton("-"))
                {
                    //entity.RemoveComponent(index);
                    curEntity.DelComponent(com);
                }
            }
            EditorGUILayout.EndHorizontal();

            //Draw the icon
            if (ComponentsPool <IZComponent> .IsSystem(com))
            {
                GUI.DrawTexture(new Rect(rect.x + 1, rect.y + 1,
                                         iconSize - 2, iconSize - 2), IconHelper.SystemsHierarchyIcon);
            }
            else
            {
                GUI.DrawTexture(new Rect(rect.x + 1, rect.y + 1,
                                         iconSize - 2, iconSize - 2), IconHelper.EntityHierarchyIcon);
            }


            if (bUnfolded)
            {
                InspectorDrawer.DrawObjectMember(com);
            }

            EditorGUILayout.EndVertical();
        }
コード例 #3
0
ファイル: ZEntity.cs プロジェクト: zzh-527/ZECS
        /// <summary>
        /// Gets the component.
        /// </summary>
        /// <returns>The component.</returns>
        /// <typeparam name="T">The 1st type parameter.</typeparam>
        public T GetComponent <T>()
        {
            IZComponent c = components.Find((a) => a.GetType() == typeof(T) || a.GetType().IsSubclassOf(typeof(T)));

            if (c != null)
            {
                return((T)c);
            }

            return(default(T));
        }
コード例 #4
0
ファイル: ZEntity.cs プロジェクト: zzh-527/ZECS
        /// <summary>
        /// Sets the get component in sub entities.
        /// </summary>
        /// <value>The get component in sub entities.</value>
        public T GetComponentInSubEntities <T>() where T : IZComponent
        {
            IZComponent t = GetComponent <T> () as IZComponent;

            if (t == null && subEntities != null)
            {
                foreach (var sub in subEntities)
                {
                    t = sub.GetComponent <T> () as IZComponent;
                    if (t != null)
                    {
                        return((T)t);
                    }
                }
            }
            return((T)t);
        }
コード例 #5
0
ファイル: ZEntity.cs プロジェクト: zzh-527/ZECS
 /// <summary>
 /// Dels the component.
 /// </summary>
 /// <param name="com">COM.</param>
 public void DelComponent(IZComponent com)
 {
     components.Remove(com);
 }
コード例 #6
0
ファイル: ZEntity.cs プロジェクト: zzh-527/ZECS
 /// <summary>
 /// Adds the component.
 /// </summary>
 /// <param name="com">COM.</param>
 public void AddComponent(IZComponent com)
 {
     components.Add(com);
 }
コード例 #7
0
        /// <summary>
        /// Saves the component data.
        /// </summary>
        /// <returns>The component data.</returns>
        /// <param name="com">COM.</param>
        static private string SaveComponentData(IZComponent com)
        {
            string strData = EditorJsonUtility.ToJson(com, true);

            return(ComponentPrefix + "\n" + com.GetType().Name + "\n" + strData + "\n" + ComponentPrefix + "\n");
        }
コード例 #8
0
ファイル: ZMemory.cs プロジェクト: sungaila/uebersetzerbauSWP
        private void SetupLabels(IZComponent parent)
        {
            foreach (IZComponent component in parent.SubComponents)
            {
                ZRoutineLabel routineLabel = component as ZRoutineLabel;
                ZJumpLabel jumpLabel = component as ZJumpLabel;
                ZBranchLabel branchLabel = component as ZBranchLabel;

                if (routineLabel != null && routineLabel.TargetAddress == null)
                {
                    ZRoutine foundRoutine = _highMem.Routines.FirstOrDefault(r => r.Label.Name == routineLabel.Name);

                    if (foundRoutine != null)
                        routineLabel.TargetAddress = new ZPackedAddress(foundRoutine.Label.TargetAddress.Absolute);
                    else
                        throw new Exception(String.Format("The ZRoutineLabel targets a ZRoutine that does not exist. A routine named '{0}' has not been found.", routineLabel.Name));
                }

                if (jumpLabel != null && (jumpLabel.TargetAddress == null || jumpLabel.SourceComponent == null))
                {
                    IZLabeledComponent foundComponent = GetAllLabeledComponents().FirstOrDefault(c => c.Label.Name == jumpLabel.Name);

                    if (foundComponent != null)
                        jumpLabel.TargetAddress = new ZAddress(foundComponent.Label.TargetAddress.Absolute);
                    else
                        throw new Exception(String.Format("The ZJumpLabel targets a ZComponent that does not exist. A component named '{0}' has not been found.", jumpLabel.Name));

                    jumpLabel.SourceComponent = parent;
                }

                if (branchLabel != null && ((branchLabel.RoutineReturnValue != null && branchLabel.TargetAddress == null) || (branchLabel.TargetAddress == null || branchLabel.SourceComponent == null)))
                {
                    if (branchLabel.Name != null)
                    {
                        IZLabeledComponent foundComponent = GetAllLabeledComponents().FirstOrDefault(c => c.Label.Name == branchLabel.Name);

                        if (foundComponent != null)
                            branchLabel.TargetAddress = new ZAddress(foundComponent.Label.TargetAddress.Absolute);
                        else
                            throw new Exception(String.Format("The ZBranchLabel targets a ZComponent that does not exist. A component named '{0}' has not been found.", branchLabel.Name));
                    }

                    branchLabel.SourceComponent = parent;
                }

                SetupLabels(component);
            }
        }
コード例 #9
0
        /// <summary>
        /// Draws the entity.
        /// </summary>
        void DrawEntity()
        {
            EditorGUI.BeginChangeCheck();

            var componentColor = Color.HSVToRGB(0.5f, 0.7f, 1f);

            componentColor.a = 0.15f;
            entityStyle      = new GUIStyle(GUI.skin.box);

            entityStyle.normal.background = InspectorDrawer.createTexture(2, 2, componentColor);

            List <IZComponent> coms = curEntity.GetComponents <IZComponent> ();


            //draw current selected entity
            EditorGUILayout.BeginVertical(entityStyle);

            //show the entity name
            EditorGUILayout.BeginHorizontal();

            EditorGUILayout.LabelField("Entity Name: " + curEntity.Name);
            //curEntity.Name = EditorGUILayout.TextField (curEntity.Name);
            EditorGUILayout.EndHorizontal();

            //show component info
            EditorGUILayout.BeginHorizontal();

            EditorGUILayout.LabelField("Component x " + coms.Count, GUILayout.MaxWidth(100));
            GUILayout.FlexibleSpace();

            //show the component menu
            IZComponent c = curEntity.EType == EntityType.Entity ?
                            ComponentsPool <IZComponent> .DrawAddComponentMenu() :
                            ComponentsPool <IZComponent> .DrawAddSystemMenu();

            if (c != null)
            {
                var com = ComponentsPool <IZComponent> .CreateComponent(c.GetType());

                curEntity.AddComponent(com);
            }
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.EndVertical();


            //Draw Component
            componentColor   = Color.HSVToRGB(0.9f, 0.1f, 0.9f);
            componentColor.a = 0.15f;
            entityStyle      = new GUIStyle(GUI.skin.box);

            entityStyle.normal.background = InspectorDrawer.createTexture(2, 2, componentColor);

            ///EditorGUILayout.Space();

            foreach (IZComponent com in coms)
            {
                DrawComponent(com);
            }


            if (EditorGUI.EndChangeCheck())
            {
                // Code to execute if GUI.changed
                // was set to true inside the block of code above.

                if (poolConfig != null && poolConfig.CurPool != null)
                {
                    //Debug.Log("EndChangeCheck");
                    EntityPoolEditorBuildUtils.SaveEntity(curEntity);

                    serializedObject.SetIsDifferentCacheDirty();
                    EditorApplication.DirtyHierarchyWindowSorting();
                    EditorApplication.RepaintProjectWindow();
                    //AssetDatabase.Refresh ();
                    //EditorApplication.
                }
            }
        }