Exemplo n.º 1
0
 protected override void Start()
 {
     base.Start();
     if (!gameObject.name.Equals("UserDefinedTarget"))
     {
         OnInstantiate.Invoke(this);
     }
 }
Exemplo n.º 2
0
    /// <summary>
    /// Called by the server on the clients to instantiate a Synchronized GameObject
    /// </summary>
    private void InstantiateSyncObject(string _prefabName, string _GUID, Vector3 _position, Quaternion _rotation, string _parentName = null)
    {
        if (string.IsNullOrEmpty(_GUID))
        {
            Debug.LogError("You tried to instantiate a Game Object without a GUID");
            return;
        }
        if (Resources.Load <GameObject>(_prefabName) == null)
        {
            Debug.LogError($"Can't find any {_prefabName} prefab in the Resources Folder");
            return;
        }

        Transform parent = null;

        if (!string.IsNullOrEmpty(_parentName))
        {
            parent = GameObject.Find(_parentName).transform;
        }

        GameObject        instance = Instantiate(Resources.Load <GameObject>(_prefabName), _position, _rotation, parent) as GameObject;
        SyncMonoBehaviour SMB      = instance.GetComponent <SyncMonoBehaviour>();

        SMB.InitializeGUID(_GUID);
        NetworkSynchronizer.Instance.AddSynchronizeObject(SMB);
        Debug.Log($"Instantiating {_prefabName} under {_parentName} at ({_position}), {_rotation} with GUID({_GUID})", instance);

        if (SMB == null)
        {
            Debug.LogError("You tried to instantiate a prefab which does not have a SyncMonoBehaviour");
            Destroy(instance);
            return;
        }

        OnInstantiate?.Invoke(SMB.gameObject);
    }
Exemplo n.º 3
0
 /// <summary>
 /// 实例化指定类型对象
 /// </summary>
 /// <typeparam name="T">对象类型</typeparam>
 /// <param name="_defaultSelfActive">默认激活状态</param>
 /// <param name="_callback">回调</param>
 /// <param name="_extraParameter">额外参数</param>
 public void Instantiate <T>(bool _defaultSelfActive, Action <IAssetBundleResult> _callback, params object[] _extraParameter) where T : UnityEngine.Object
 {
     OnInstantiate?.Invoke(_defaultSelfActive, input, _callback, _extraParameter, typeof(T));
 }