public PropertyViewModel(IPrefab prefab, IAccessor accessor, int index) { _prefab = prefab; _accessor = accessor; Value = _accessor.ToStringPrefab(_accessor.GetPrefab(prefab)); Index = index; }
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) { IPrefab prefab = null; MonoBehaviour monoBehaviour = value as MonoBehaviour; if (value is IJsonSaveable jsonSaveable) { prefab = jsonSaveable.iprefab; } else if (monoBehaviour != null) { Prefab component = monoBehaviour.GetComponent <Prefab>(); if (component != null) { prefab = component.iprefab; } } if (ShouldSerializeIPrefab(prefab)) { serializer.Serialize(writer, prefab.guid.ToString()); return; } writer.WriteComment("nulled destroyed MIA"); serializer.Serialize(writer, null); }
public static PrefabInstance Create(IPrefab prefab) { DomNode instNode = new DomNode(Schema.prefabInstanceType.Type); PrefabInstance inst = instNode.As<PrefabInstance>(); inst.m_prefab = prefab; instNode.InitializeExtensions(); inst.Resolve(null); return inst; }
public static PrefabInstance Create(IPrefab prefab) { DomNode instNode = new DomNode(Schema.prefabInstanceType.Type); PrefabInstance inst = instNode.As <PrefabInstance>(); inst.m_prefab = prefab; instNode.InitializeExtensions(); inst.Resolve(null); return(inst); }
public void RegisterPrefab(string name, IPrefab prefab) { name = ignoreCase ? name.ToLower() : name; if (entityBuilders.ContainsKey(name)) { throw new Exception($"You've already created a prefab called {name}"); } entityBuilders.Add(name, prefab); }
private StringBuilder IPrefabData(IPrefab ipre) { StringBuilder text = new StringBuilder(); Dictionary <string, object> dict = ipre.GetComponentData(); foreach (string str in dict.Keys) { text.Append("\n\tIPrefabKey: ").Append(str); } foreach (object obj in dict.Values) { if (obj.GetType() == typeof(SmartObject.SmartObjectData)) { text.Append("\n\t\t"); } } return(text); }
void OnCreatePrefab(IPrefab obj, object param) { m_prefab = obj; if (m_prefab != null) { if (m_prefab.GetObj() != null) { m_obj = GameObject.Instantiate(m_prefab.GetObj()) as GameObject; RefreshShader(m_obj); AssetManager.Instance().AddGameObjPool(this); if (m_callback != null) { m_callback(this, param); } } } else { Utility.Log.Error("Create gameobject failed {0}", m_strObjName); } }
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { string text = serializer.Deserialize <string>(reader); if (text == null) { return(null); } IPrefab prefab = GUID.Fetch(int.Parse(text)); if (prefab == null) { TBFlashLogger(Log.FromPool(string.Format("GUID.Fetch {0} was NULL // NOT FOUND", text)).WithCodepoint()); return(null); } if (prefab.zone != null) { return(prefab.zone); } if (prefab.agent != null) { return(prefab.agent); } if (prefab.iPoolable != null) { return(prefab.iPoolable); } if (prefab.prefab != null) { Component component = prefab.prefab.gameObject.GetComponent(usingType); if (component == null) { TBFlashLogger(Log.FromPool("NULL GetComponent<T> Lookup").WithCodepoint()); } return(component); } TBFlashLogger(Log.FromPool("NULL GetComponent<T> Lookup").WithCodepoint()); return(null); }
private PositionRotation SamplePositionRotation(GameObject gameObjectInstance, int maxSpawnAttempt, Vector3 positionIn, float rotationY, Vector3 size) { Vector3 gameObjectBoundingBox; Vector3 rotationOut = Vector3.zero; Vector3 positionOut = Vector3.zero; IPrefab gameObjectInstanceIPrefab = gameObjectInstance.GetComponent <IPrefab>(); bool canSpawn = false; int k = 0; while (!canSpawn && k < maxSpawnAttempt) { gameObjectInstanceIPrefab.SetSize(size); gameObjectBoundingBox = gameObjectInstance.GetBoundsWithChildren().extents; positionOut = gameObjectInstanceIPrefab.GetPosition(positionIn, gameObjectBoundingBox, _rangeX, _rangeZ); rotationOut = gameObjectInstanceIPrefab.GetRotation(rotationY); Collider[] colliders = Physics.OverlapBox(positionOut + _arena.position, gameObjectBoundingBox, Quaternion.Euler(rotationOut), 1 << 0); canSpawn = IsSpotFree(colliders, gameObjectInstance.CompareTag("agent")); k++; } if (canSpawn) { return(new PositionRotation(positionOut, rotationOut)); } return(null); }
public static GameObjectInfo GetFromGameObject(GameObject go) { GameObjectInfo r = new GameObjectInfo(); IPrefab iprefab = go.GetComponent <IPrefab>(); if (iprefab == null) { Debug.Log("WTF"); return(null); } r.instanceName = go.name; r.position = go.transform.localPosition; r.rotation = go.transform.localRotation; r.scale = go.transform.localScale; if (go.transform.parent != null) { r.parentInstanceName = go.transform.parent.name; } else { r.parentInstanceName = "noParent"; } return(r); }
public void Resolve(UniqueNamer namer) { try { m_updating = true; Uri resUri = GetAttribute<Uri>(Schema.prefabInstanceType.prefabRefAttribute); if (resUri != null) m_prefab = Globals.ResourceService.Load(resUri) as IPrefab; if (m_prefab == null) return; // update name and uri if(resUri == null) SetAttribute(Schema.prefabInstanceType.prefabRefAttribute, m_prefab.Uri); IGameObjectGroup gobgroup = DomNode.As<IGameObjectGroup>(); if (string.IsNullOrWhiteSpace(gobgroup.Name)) gobgroup.Name = "PrefabInst_" + m_prefab.Name; DomNode[] gobs = DomNode.Copy(m_prefab.GameObjects.AsIEnumerable<DomNode>()); HashSet<string> gobIds = new HashSet<string>(); gobgroup.GameObjects.Clear(); foreach (var gobNode in gobs) { gobNode.InitializeExtensions(); IGameObject gob = gobNode.As<IGameObject>(); m_intsToOriginal.Add(gobNode, gob.Name); gobIds.Add(gob.Name); ObjectOverride objectOverride; m_overridesMap.TryGetValue(gob.Name, out objectOverride); updateNode(gobNode, objectOverride); string name = gob.Name; if (namer != null) gob.Name = namer.Name(gob.Name); gobgroup.GameObjects.Add(gob); } // cleanup m_overridesmap List<string> overrideIds = new List<string>(m_overridesMap.Keys); foreach (string id in overrideIds) { if (!gobIds.Contains(id)) { ObjectOverride objectOverride = m_overridesMap[id]; m_overridesMap.Remove(id); m_overrideList.Remove(objectOverride); } } } finally { m_updating = false; } }
public BooleanPropertyViewModel(IPrefab prefab, IAccessor accessor, int index) : base(prefab, accessor, index) { }
public void CreateGameObject(ref string strObjName, CreateGameObjectEvent callBack, object custumParam = null, TaskPriority ePriority = TaskPriority.TaskPriority_Normal) { m_callback = callBack; m_strObjName = strObjName; m_prefab = AssetManager.Instance().CreatePrefab(strObjName, OnCreatePrefab, custumParam, ePriority); }
private static bool ShouldSerializeIPrefab(IPrefab i) { return(i?.isPooled == false && i.guid != GUID.None && (!(i.prefab != null) || i.prefab.commitable)); }